package Server.Poker.PDK;

import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Timer;
import java.util.TimerTask;

import org.apache.commons.lang.StringUtils;
import org.json.JSONObject;

import Server.Agent.GameAgent;
import Server.Agent.GameDB;
import Server.Model.Base.IRoom;
import Server.Model.Base.IServerUserItem;
import Server.Model.Base.SHMUser;
import Server.Model.Hall.QpGameMgr;
import Server.Model.Hall.dthall;
import activity.ActivityMgr;
import activity.UserActionActivity;
import admin.AdminRedis;
import club.ClubMgr;
import club.ClubRedis;
import common.routine.CommonDef;
import common.routine.PublishDef;
import rank.RankMgr;
import redis.protocal.DbInfoMgr;
import redis.protocal.DwcRedisRecord;
import redis.protocal.UserRedisInfo;
import robot.GoldMgr;
import robot.Robot;
import robot.RobotMgr;
import Server.Model.Base.SecShmUser;
import Server.Model.Base.UserGoldChange;
import Server.Model.Base.UserRmbChange;


public class PDKZTable extends IRoom {
	int mTableID;
	boolean m_bLocked; // 锁定标志
	String m_szPassint; // 密码

	int GetTableID() {
		return mTableID;
	};

	int m_wBombTime; // 炸弹倍数
	int m_bLandScore; // 地主分数
	int m_wOutBombCount; // 炸弹数目
	int m_wFirstUser; // 首叫用户
	int m_wBankerUser; // 庄家用户
	int m_wCurrentUser; // 当前玩家
	int m_bScoreInfo[] = new int[3]; // 叫分信息

	int m_bMingCard; // 明牌扑克
	int m_bCurrentState; // 当前状态
	int m_bCallScoreTimes[] = new int[Constants.DDZ_PLAYER]; // 叫分次数
	int m_bCallScoreTag[] = new int[Constants.DDZ_PLAYER]; // 叫分判断
	int m_bScoreTimes[] = new int[Constants.DDZ_PLAYER]; // 分数倍数
	int m_bCallBanker[] = new int[Constants.DDZ_PLAYER]; // 叫庄信息
	int m_bHaveSendCard; // 发牌判断

	int m_wTurnWiner; // 胜利玩家
	int m_bTurnCardCount; // 出牌数目
	int m_bTurnCardData[] = new int[20]; // 出牌列表
	boolean m_bUserTrustee[] = new boolean[Constants.DDZ_PLAYER]; // 玩家托管

	int m_bBackCard[] = new int[0]; // 游戏底牌
	int m_bCardCount[] = new int[3]; // 扑克数目
	int m_bOutCardCount[] = new int[3]; // 出牌次数
	int m_bHandCardData[][] = new int[3][20]; // 手上扑克
	int m_bGameStatus; // 游戏状态
	boolean m_bGameStarted; // 开始标志
	int m_dwTimeStart; // 开始时间
	//新加变量
	boolean m_bTableStarted;
	int m_byRound;
	int m_byMaxRound;
	
	public String m_roomParam;
	
	long m_dismissTimer;
	int m_paiMode = 0;
	int m_jiesuanMode = 0;
	int m_byAgreeDismiss[] = new int[3];
	
	long m_LookOnUserID[] = new long[50]; // 观众

	public int m_byZhuang;// 当前庄位置

	public int m_vecWinScore[] = new int[3];
	public int m_vecLoseScore[] = new int[3];
	public int m_vecCardType[] = new int[3];
	public int m_vecRoundScore[] = new int[3];
	public int m_vecResultScore[] = new int[3];
	public double m_doubleVecResultScore[] = new double[3];
	public double m_doubleKouWinResultScore[] = new double[3];
	public int m_kouWinSumJu = 0;
	public int m_kouWinCurrJu = 0;
	public int m_vecWinCount[] = new int[3];
	public int m_vecGuanMenCount[] = new int[3];
	public int m_vecBombCount[] = new int[3];
	
	public int m_yuPai[] = new int[3];
	public int m_lastOutCard[] = new int[2];//最后两张牌
	
	public int m_bombArray[] = new int [3];
	public int m_boomCountArray[] = new int[3];
	
	public CMD_CURRENT_OutCard currentCard;
	

	int m_lGameTaxScore; // 游戏税收
	int m_dwPlayerID[] = new int[Constants.MAX_CHAIR]; // 玩家 I D
	tagScoreInfo m_ScoreInfo[] = new tagScoreInfo[Constants.MAX_CHAIR]; // 游戏积分
	{
		for (int i = 0; i < m_ScoreInfo.length; i++) {
			m_ScoreInfo[i] = new tagScoreInfo();
		}
	}
	PlayerBase mPlayers[] = new PlayerBase[Constants.DDZ_PLAYER];

	ServerUserItem m_pIUserItem[] = new ServerUserItem[Constants.DDZ_PLAYER]; // 用户指针
	{
		for (int i = 0; i < m_pIUserItem.length; i++) {
			m_pIUserItem[i] = new ServerUserItem();
		}
	}
	int mSequentWinCount[] = new int[Constants.DDZ_PLAYER];

	PDKLogic_Server m_GameLogic = new PDKLogic_Server(); // 游戏逻辑
	String m_curStage = "";
	int m_aiDelayTime = 0;
	int m_lCellScore;
	int mLogicTime;
	int mCntRealUser;
	int mKXTime;
	int mActiveTime;
	int m_iDifen;

	PDKTableMgr m_objAppHandler;
	static int g_AndroidUIDIndex;

	void SetTableID(int lTableID) {
		mTableID = lTableID;
	}

	public void setAppHandler(PDKTableMgr handler) {
		m_objAppHandler = handler;
	}

	public PDKZTable() {
		mLogicTime = 0;
		m_objAppHandler = null;
		mTableID = 0;
		m_bRemove = false;

		Init();
	}

	void setBase(int lCellScore) {
		mKXTime = 0;
		m_lCellScore = lCellScore;
	}

	int getBase() {
		return m_lCellScore;
	}
	
	public boolean m_bRemove = false;
	
	public void DelayRemove() {
		m_bRemove = true;
	}
	public void ResetKillFlag() {
		m_bRemove = false;
	}

	public boolean ShouldBeRemoved() {
		return m_bRemove;
	}

	public void OnUserStandUp(int _Uid,boolean leaveroom) {
		if (_Uid == 0) {
			return;
		}

		int wChairID = FindSeat(_Uid);
		if(m_bTableStarted == true && this.isDwcType() && leaveroom == true){
			//真金情况可以退出
			SUBCMD_S_StandUp cmd = new SUBCMD_S_StandUp();
			cmd.m_lUid = _Uid;
			cmd.m_wUserChairID = wChairID;
			cmd.m_dwTableID = m_dwTableID;
			cmd.leaveRoom = leaveroom ?1:0;
			
			for(int i = 0; i < 3; i ++){
				if(m_pIUserItem[i].dwUserID > 0 && _Uid != m_pIUserItem[i].dwUserID)
				{
					SendData(m_pIUserItem[i].dwUserID, cmd.getJsonData());
				}
			}
			
			m_pIUserItem[wChairID].Init();
			if(hasAutoDianKong()){
				onUserQuitForDianKong(_Uid);
			}
			QpGameMgr.getInstance().OnRemoveUserRoom(_Uid);
			//检查是否全部是机器人
			int realCnt = 0;
			for(int i = 0; i < 3; i ++){
				if(m_pIUserItem[i].dwUserID > 0 && m_pIUserItem[i].isAndroidUser == 0)
				{
					realCnt++;
				}
			}
			if(realCnt == 0){
				OnEventGameEnd(0, null,Constants.GAME_END_DISMISS);
				return;
			}
			return;
		}
		
		if(m_bTableStarted == false && wChairID != 0 && leaveroom == true){
			SUBCMD_S_StandUp cmd = new SUBCMD_S_StandUp();
			cmd.m_lUid = _Uid;
			cmd.m_wUserChairID = wChairID;
			cmd.m_dwTableID = m_dwTableID;
			cmd.leaveRoom = leaveroom ?1:0;
			SendData(Constants.INVALID_CHAIR, cmd.getJsonData());
		}


		if (m_bTableStarted == false && leaveroom == true) {
			if (wChairID > 0 && wChairID < 3) {
				m_pIUserItem[wChairID].Init();
				if(hasAutoDianKong()){
					onUserQuitForDianKong(_Uid);
				}
				QpGameMgr.getInstance().OnRemoveUserRoom(_Uid);
			} else {
			}
		} else {
			if (wChairID < 3) {
				m_pIUserItem[wChairID].cbOnline = Constants.US_OFFLINE;
			}
		}
	}

	boolean hasUser(int uid) {
		for (int i = 0; i < Constants.DDZ_PLAYER; i++) {
			if (m_pIUserItem[i] != null && m_pIUserItem[i].getUid() != 0 ) {// 有真人
				tagUserData pUserData = m_pIUserItem[i].GetUserData();
				if (pUserData.dwUserID == uid) {
					return true;
				}
			}
		}
		return false;
	}

	boolean isEmpty() {
		for (int i = 0; i < Constants.DDZ_PLAYER; i++) {
			if (m_pIUserItem[i] != null && m_pIUserItem[i].getUid() != 0) {// 有真人
				return false;
			}
		}
		return true;
	}

	void Init() {
		m_bGameStatus = Constants.GS_WK_FREE;
		
		// 游戏变量
		m_wBombTime = 1;
		m_bLandScore = 0;
		m_wFirstUser = 0;
		m_bMingCard = 0;
		m_bHaveSendCard = 0;
		m_bCurrentState = 0;
		m_wOutBombCount = 0;
		m_wFirstUser = Constants.INVALID_CHAIR;
		m_wBankerUser = Constants.INVALID_CHAIR;
		m_wCurrentUser = Constants.INVALID_CHAIR;
		Constants.memset(m_bScoreTimes, 0, Constants.sizeof(m_bScoreTimes));
		Constants.memset(m_bCallScoreTimes, 0, Constants.sizeof(m_bCallScoreTimes));
		Constants.memset(m_bCallScoreTag, 0, Constants.sizeof(m_bCallScoreTag));
		Constants.memset(m_bCallBanker, 0, Constants.sizeof(m_bCallBanker));
		Constants.memset(m_bScoreInfo, 0, Constants.sizeof(m_bScoreInfo));

		// 运行信息
		m_bTurnCardCount = 0;
		m_wTurnWiner = Constants.INVALID_CHAIR;
		Constants.memset(m_bTurnCardData, 0, Constants.sizeof(m_bTurnCardData));
		Constants.memset(m_bUserTrustee, 0);

		// 扑克信息
		Constants.memset(m_bBackCard, 0, Constants.sizeof(m_bBackCard));
		Constants.memset(m_bCardCount, 0, Constants.sizeof(m_bCardCount));
		Constants.memset(m_bOutCardCount, 0, Constants.sizeof(m_bOutCardCount));
		Constants.memset(m_bHandCardData, 0);

		// memset(m_pIUserItem,0,sizeof(m_pIUserItem));

		for (int i = 0; i < Constants.DDZ_PLAYER; i++) {
			//m_pIUserItem[i] = new ServerUserItem();
			mPlayers[i] = null;
			mSequentWinCount[i] = 0;
		}

		m_bGameStatus = Constants.GS_WK_FREE; // 初始化状态
		m_bGameStarted = false;
		m_dwTimeStart = 0;

		m_lCellScore = 0;

		mKXTime = 0;
		mCntRealUser = 1;
		
		m_dismissTimer = 0;
		m_byAgreeDismiss[0] = 0;
		m_byAgreeDismiss[1] = 0;
		m_byAgreeDismiss[2] = 0;
		Constants.memset(m_LookOnUserID, 0, Constants.sizeof(m_LookOnUserID)); //
		m_byRound = 0;
		m_byMaxRound = 0;
		m_byZhuang = 0;
		for (int i = 0; i < 3; i++) {
			m_vecWinScore[i] = 0;
			m_vecLoseScore[i] = 0;
			m_vecResultScore[i] = 0;
			m_doubleVecResultScore[i] = 0;
			m_bombArray[i] = 0;
			m_boomCountArray[i] = 0;
			m_vecWinCount[i] = 0;
			m_vecGuanMenCount[i] = 0;
			m_vecBombCount[i] = 0;
		}
		
		currentCard = new CMD_CURRENT_OutCard();
	
	}

	void UnInit() {
		for (int i = 0; i < Constants.DDZ_PLAYER; ++i) {
			if (mPlayers[i] != null) {
				// delete mPlayers[i];
			}
			mPlayers[i] = null;
			if (m_pIUserItem[i] != null) {
				m_pIUserItem[i].Init();;
			}
		}
	}

	public boolean SendGameMessage(int wSubCmdID, Object pData, int wDataSize, int wChairID, String data) {
		MSG_FOR_TABLE subcmd = new MSG_FOR_TABLE();
		subcmd.wSubCmd = wSubCmdID;
		subcmd.wChairID = wChairID;
		subcmd.strData = data;
		subcmd.byData = pData;
		String sData = subcmd.getJsonData();
		for (int i = 0; i < Constants.DDZ_PLAYER; ++i) {
			if (mPlayers[i] != null && mPlayers[i].GetChairID() == wChairID) {
				ServerUserItem pUserItem = GetServerUserItem(wChairID);
				if (pUserItem != null && pUserItem.IsAndroidUser()) {
					SendPacket(subcmd, 0);
				} else {
					mPlayers[i].SendPacket(Constants.PktID_DDZ_TableDataResult, subcmd, 0, sData);
				}
			}
		}
		return true;
	}


	boolean SendPacket(Object pMsg, int wSize) {
		OnRecv(pMsg, wSize);
		return true;
	}

	boolean ProcessRecvdPacket(int dwMaxPacketSize) {
		return true;
	}

	boolean OnRecv(Object pMsg, int wSize) {
		MSG_FOR_TABLE pTableCmd = (MSG_FOR_TABLE) pMsg;
		OnGameMessage(pTableCmd.wSubCmd, pTableCmd.byData, 0, GetServerUserItem(pTableCmd.wChairID));
		return true;
	}

	boolean OnRecv(int uid, String[] vecArg) {

		for (int i = 0; i < Constants.DDZ_PLAYER; i++) {
			ServerUserItem pIUserItem = GetServerUserItem(i);

			if (pIUserItem != null && pIUserItem.GetUserID() == uid) {
				MSG_FOR_TABLE pTableCmd = new MSG_FOR_TABLE();
				pTableCmd.wSubCmd = Constants.atoi(vecArg[1]);
				pTableCmd.wChairID = i;
				String data = vecArg.length >= 4 ? vecArg[3] : "";
				pTableCmd.strData = data;
				String[] vecArg1 = pTableCmd.strData.split("\\.");
				OnGameMessage(pTableCmd.wSubCmd, vecArg1, GetServerUserItem(pTableCmd.wChairID));
			}
		}

		return true;
	}

	void Update(int frameTime) {
		m_DealTime = (int) (System.currentTimeMillis() / 1000);
		mLogicTime += frameTime;
		for (int i = 0; i < Constants.DDZ_PLAYER; ++i) {
			if (mPlayers[i] != null && m_pIUserItem[i] != null) {
				mPlayers[i].Update(frameTime);
			}
		}
		ProcessRecvdPacket(4096);
		mKXTime += frameTime;
	}

	static int _game_round_count = 0;
	void changeGoodCardForRobot(int index1,int index2){
		int limitcard = 8 + CommonDef.getRandomInt(5);
		int count = 2 + CommonDef.getRandomInt(3);
		for(int i = 0;i < count;i++){
			int ch1 = -1;
			int ch2 = -1;
			Map<Integer,Integer> nummap = new HashMap<Integer,Integer>();
			for(int k = 0;k < 16;k++){
				int h1 = m_GameLogic.GetCardLogicValue(m_bHandCardData[index1][k]);
				if(h1 < 10){
					if(nummap.containsKey(h1)){
						nummap.put(h1,nummap.get(h1) + 1);
					}else{
						nummap.put(h1,1);
					}
				}
			}
			Map<Integer,Integer> nummap2 = new HashMap<Integer,Integer>();
			for(int k = 0;k < 16;k++){
				int h1 = m_GameLogic.GetCardLogicValue(m_bHandCardData[index2][k]);
				if(h1 < 10){
					if(nummap2.containsKey(h1)){
						nummap2.put(h1,nummap2.get(h1) + 1);
					}else{
						nummap2.put(h1,1);
					}
				}
			}
			int value = -1;
			for(Integer key : nummap.keySet()){
				if(nummap.get(key) <= 1){
					value = key;
					if(nummap2.containsKey(value) && nummap2.get(value) == 3){
						//保证不会换成炸弹
						continue;
					}
					break;
				}
			}
			if(value == -1){
				for(int k = 0;k < 16;k++){
					int h1 = m_GameLogic.GetCardLogicValue(m_bHandCardData[index1][k]);
					if(h1 < 10){
						ch1 = k;
						break;
					}
				}
			}else{
				for(int k = 0;k < 16;k++){
					int h1 = m_GameLogic.GetCardLogicValue(m_bHandCardData[index1][k]);
					if(h1 == value){
						ch1 = k;
						break;
					}
				}
			}
			if(ch1 < 0)
				continue;
			for(int k = 0;k < 16;k++){
				int h2 = m_GameLogic.GetCardLogicValue(m_bHandCardData[index2][k]);
				if(h2 >= limitcard){
					ch2 = k;
					break;
				}
			}
			if(ch1 >= 0 && ch2 >= 0){
				int tmp = m_bHandCardData[index1][ch1];
				m_bHandCardData[index1][ch1] = m_bHandCardData[index2][ch2];
				m_bHandCardData[index2][ch2] = tmp;
			}
		}
	}
	boolean OnEventGameStart() {
		_game_round_count++;

		// printf("---------------------------- Round %d
		// ----------------------------\n", _game_round_count );
		// 设置状态
		SetGameStatus(Constants.GS_WK_PLAYING);
		m_kouWinSumJu = GoldMgr.getInstance().getKouWinJuShuInClub();

		for (int wChairID = 0; wChairID < Constants.DDZ_PLAYER; ++wChairID) {
			ServerUserItem pServerUserItem = GetServerUserItem(wChairID);
			if (pServerUserItem != null) {
				tagUserData pUserData = pServerUserItem.GetUserData();
				pUserData.lScore -= m_lCellScore;
				SendUserScore(pServerUserItem);
			}
		}
		//设置ai信息
		for(int i = 0;i < Constants.DDZ_PLAYER;i++){
			if(mPlayers[i] != null && m_pIUserItem[i].isAndroidUser == 2){
				AIPlayer ai = (AIPlayer) mPlayers[i];
				for(int k = 0;k < Constants.DDZ_PLAYER;k++){
					if(m_pIUserItem[k].isAndroidUser == 2){
						ai.m_robotSign[k] = 1;
						ai.m_wBankerUser = 0;
					}else{
						ai.m_robotSign[k] = 0;
						ai.m_wBankerUser = 0;
					}
				}
			}
		}
		if(this.isDwcType() && GoldMgr.getInstance().getNeedAutoDianKong() == 1){
			//需要自动点控则请求
			if(!hasAutoDianKong()){
				 requestDianKong(cloneServerPdkUserPack(m_pIUserItem));
			}else{
				int uid = getDianKongUid();
				int seat = FindSeat(uid);
				if(seat == Constants.INVALID_CHAIR){
					clearDianKong();
				}
			}
		}
		// 混乱扑克
		int bRandCard[] = new int[48];
		m_GameLogic.RandCardList(bRandCard, Constants.sizeof(bRandCard),this.m_paiMode);
		//bRandCard = m_GameLogic.m_cbCardData.clone();
		// 分发扑克
		for (int i = 0; i < Constants.DDZ_PLAYER; i++) {
			m_bCardCount[i] = 16;
			Constants.CopyMemory(m_bHandCardData[i], bRandCard, i * m_bCardCount[i], m_bCardCount[i]);
		}
		Constants.CopyMemory(m_bBackCard, bRandCard, 48, Constants.sizeof(m_bBackCard));
		m_GameLogic.SortCardList(m_bBackCard, 0, Constants.ST_ORDER);
		//群控操作
		boolean hasrobot = false;
		ArrayList<Integer> vecEmpty = new ArrayList<>();
		for (int i = 0; i < Constants.DDZ_PLAYER; i++) {
			if(m_pIUserItem[i].isAndroidUser == 2){
				hasrobot = true;
				vecEmpty.add(i);
			}
		}
		boolean qunkonged = false;
		if(this.isDwcType() && hasrobot && m_doubleDiFen >= GoldMgr.getInstance().getRobotRmbDiFenControl() 
				&& CommonDef.getRandomInt(100) < GoldMgr.getInstance().getRobotRmbDiFenControlRate()){
			//真金模式，有机器人么，底分超过控制，开始强制换牌
			int robotIndex = vecEmpty.get(CommonDef.randInt(0,vecEmpty.size()));
			int index1 = (robotIndex + 1) % Constants.DDZ_PLAYER;
			int index2 = (robotIndex + 2) % Constants.DDZ_PLAYER;
			changeGoodCardForRobot(robotIndex,index1);
			if(CommonDef.getRandomInt(100) > GoldMgr.getInstance().getPdkCard2HuanRate())
				changeGoodCardForRobot(robotIndex,index2);
			qunkonged = true;
		}

		if(qunkonged == false && hasrobot && GoldMgr.getInstance().getQunKongRev("PDK",m_doubleDiFen) > 0){
			//真金模式普通控制
			int robotIndex = vecEmpty.get(CommonDef.randInt(0,vecEmpty.size()));
			int index1 = (robotIndex + 1) % Constants.DDZ_PLAYER;
			int index2 = (robotIndex + 2) % Constants.DDZ_PLAYER;
			changeGoodCardForRobot(robotIndex,index1);
			if(CommonDef.getRandomInt(100) > GoldMgr.getInstance().getPdkCard2HuanRate())
				changeGoodCardForRobot(robotIndex,index2);
			qunkonged = true;
		}
		if ((this.isGoldType() || this.isDwcType() || this.isZuJuType()) && (qunkonged == false && CommonDef.getRandomInt(100) < m_qunKongRate  * 100)){
			double wonRate[] = new double[3];
			boolean needAdjust = false;
			for(int i = 0;i < 3;i++){
				SHMUser user = dthall.getInstance().getUserInfo(m_pIUserItem[i].dwUserID);
				if(user != null){
					if(this.isGoldType())
						wonRate[i] = user.getUserGoldWonRate();
					else if(this.isDwcType())
						wonRate[i] = user.getUserRmbWonRate();
					else if(this.isZuJuType())
						wonRate[i] = user.getUserZuJuWonRate();
					if(wonRate[i] <= m_qunKongMinTh || wonRate[i] >= m_qunKongMaxTh)
						needAdjust = true;
				}else{
					wonRate[i] = -10000;
				}
			}
			if(needAdjust){
				//需要群控处理,先对牌进行打分,在替换牌
				int paiScore[] = new int[3];
				int origPai[][] = new int[3][20];
				for(int i = 0;i < 3;i++){
					paiScore[i] = getPaiScore(m_bHandCardData[i]);
					Constants.CopyMemory(origPai[i], m_bHandCardData[i], 0, 16);
				}
				//换牌
				for(int i = 0;i < 3;i++){
					int rateIndex = getRankIndex(wonRate,-100.0);
					wonRate[rateIndex] = -10000;
					int scoreIndex = getRankIndex(paiScore,-100);
					paiScore[scoreIndex] = -10000;
					Constants.CopyMemory(m_bHandCardData[i], origPai[scoreIndex], 0, 16);
				}
			}
		}else{
			//判断是否存在点控
			if(hasAutoDianKong() && CommonDef.getRandomInt(100) < GoldMgr.getInstance().getDianKongValidRate()){
				double wonRate[] = new double[3];
				for(int i = 0;i < 3;i++){
					if(m_pIUserItem[i].dwUserID > 0){
						wonRate[i] = getDianKongRate(m_pIUserItem[i].dwUserID);
					}else{
						wonRate[i] = -10000;
					}
				}
				//开始群控
				int paiScore[] = new int[3];
				int origPai[][] = new int[3][20];
				for(int i = 0;i < 3;i++){
					paiScore[i] = getPaiScore(m_bHandCardData[i]);
					Constants.CopyMemory(origPai[i], m_bHandCardData[i], 0, 16);
				}
				//换牌
				for(int i = 0;i < 3;i++){
					int rateIndex = getRankIndex(wonRate,-100.0);
					wonRate[rateIndex] = -10000;
					int scoreIndex = getRankIndex(paiScore,-100);
					paiScore[scoreIndex] = -10000;
					Constants.CopyMemory(m_bHandCardData[i], origPai[scoreIndex], 0, 16);
				}
			}
		}
		// 随机叫庄
		m_wFirstUser = 0;// rand()%DDZ_PLAYER;
		m_wCurrentUser = m_wFirstUser;
		m_bMingCard = m_bHandCardData[m_wCurrentUser][(Constants.rand() % 16)];

		// 发送扑克
		CMD_S_SendAllCard SendAllCard = new CMD_S_SendAllCard();
		SendAllCard.wCurrentUser = m_wCurrentUser;

		// 手上扑克
		// Constants.CopyMemory(SendAllCard.bCardData, m_bHandCardData,
		// Constants.sizeof(m_bHandCardData));
		SendAllCard.bCardData = m_bHandCardData.clone();
		// 底牌扑克
		Constants.CopyMemory(SendAllCard.bBackCardData, m_bBackCard, 0);

		String sData = SendAllCard.getJsonData();
		SendTableData(Constants.INVALID_CHAIR, Constants.SUB_S_SEND_CARD, SendAllCard, 0, sData);
		
		
		
		
		if (m_byRound == 0) {
			m_byRound = 1;
		}
		OnRoundInfoChange();
		SUBCMD_S_round cmd = new SUBCMD_S_round();
		cmd.round = m_byRound;
		SendData(Constants.INVALID_CHAIR, cmd.getJsonData());

		// 排列扑克
		for (int i = 0; i < Constants.DDZ_PLAYER; i++) {
			m_GameLogic.SortCardList(m_bHandCardData[i], m_bCardCount[i], Constants.ST_ORDER);
		}
		
		
		// 设置变量
		if (m_wBankerUser == Constants.INVALID_CHAIR){
			for(int user =0;user < 3;user++){
				for(int i=0; i<16; i++){
					int value = m_bHandCardData[user][i];
					if(value == 0x33){
						m_wBankerUser = user;
						break;
					}
				}
			}
		}

		// 设置状态
		SetGameStatus(Constants.GS_WK_PLAYING);

		// 发送底牌
		//m_bCardCount[m_wBankerUser] = 16;
		//Constants.CopyMemory(m_bHandCardData[m_wBankerUser],16, m_bBackCard, Constants.sizeof(m_bBackCard));
		//m_GameLogic.SortCardList(m_bHandCardData[m_wBankerUser], m_bCardCount[m_wBankerUser], Constants.ST_ORDER);

		// 出牌信息
		m_bTurnCardCount = 0;
		m_wTurnWiner = m_wBankerUser;
		m_wCurrentUser = m_wBankerUser;

		// 发送消息
		CMD_S_GameStart GameStart = new CMD_S_GameStart();
		GameStart.wLandUser = m_wBankerUser;
		GameStart.bLandScore = m_bLandScore;
		GameStart.wCurrentUser = m_wCurrentUser;
		Constants.CopyMemory(GameStart.bBackCard, m_bBackCard, Constants.sizeof(m_bBackCard));

		String startData = GameStart.getJsonData();
		SendTableData(Constants.INVALID_CHAIR, Constants.SUB_S_GAME_START, GameStart, 0, startData);
		
		
		return true;
	}
	int getRankIndex(double[] score,double limit){
		int index = 0;
		for(int i = 0;i < score.length;i++){
			if(score[i] >= -10000 && score[i] >= limit){
				limit = score[i];
				index = i;
			}
		}
		return index;
	}
	int getRankIndex(int[] score,int limit){
		int index = 0;
		for(int i = 0;i < score.length;i++){
			if(score[i] >= -10000 && score[i] >= limit){
				limit = score[i];
				index = i;
			}
		}
		return index;
	}
	int getPaiScore(int[] pai){
		int sumScore = m_GameLogic.GetPaiEvaluateScore(pai, 17);
		return sumScore;
	}
	static int log_counter = 0;
	public void DoDismissRoomByOverTime(){
		OnEventGameEnd(0, null,Constants.GAME_END_DISMISS);
	}
	boolean OnEventGameEnd(int wChairID, ServerUserItem pIServerUserItem, int cbReason){
		if(isZuJuType() || isFreeZuJuType()){
			return OnEventGameEndZuJu(wChairID,pIServerUserItem,cbReason);
		}else if(isGoldType()){
			m_curStage = "STAGE_JIESUAN";
			m_aiDelayTime = 5 + CommonDef.getRandomInt(5);
			return onEventGameEndGold(wChairID,pIServerUserItem,cbReason);
		}else if(isDwcType()){
			m_curStage = "STAGE_JIESUAN";
			m_aiDelayTime = 5 + CommonDef.getRandomInt(5);
			return onEventGameEndDwc(wChairID,pIServerUserItem,cbReason);
		}else{
			return false;
		}
	}
	boolean onEventGameEndDwc(int wChairID, ServerUserItem pIServerUserItem, int cbReason) {
		m_byRound = m_byRound + 1;
		OnRoundInfoChange();
		
		if(cbReason == Constants.GER_NORMAL){
			// 游戏积分
			double lScore = 0;
			int winSeat = 0;
			int guanmen[] = new int[3];
			for(int i = 0; i < Constants.DDZ_PLAYER; i++){
				if(m_bCardCount[i] == 0){
					winSeat = i;
				}
			}
			double shuishourate = getShuiShou(this.GetType());
			double realshui[] = new double[3];
			for(int i = 0;i < 3;i++){
				realshui[i] = 0;
			}
			double shui = this.m_doubleDiFen * shuishourate;
			if(shui < 0.01){
				shui = 0;
			}
			//扣税
			for(int i = 0;i < 3;i++){
				if (m_pIUserItem[i].dwUserID <= 0 || Constants.US_LOOKON == m_pIUserItem[i].cbUserStatus) {
					continue;
				}
				if(m_kouShuiMode.equals("no"))
					continue;
				if(m_kouShuiMode.equals("win") && i != winSeat)
					continue;
				else if(m_kouShuiMode.equals("lose") && i == winSeat)
					continue;
				realshui[i] = shui;
				
				SecShmUser user = dthall.getInstance().getSecurityUserInfo(m_pIUserItem[i].dwUserID);
				//扣除税收先,在扣除UU逗的时候，最多扣完,不会扣成负数(系统不补贴)
				m_pIUserItem[i].lUserCoin -= shui;
				user.getRmb1v1(0 - shui);
				if(m_pIUserItem[i].isAndroidUser == 0){
					UserRmbChange.handleRmbChangeKouShui(user, shui, UserRmbChange.reason23);
					this.addEatNormalScore(shui);
					handleRmbGiveBack(m_pIUserItem[i].dwUserID,shui);
					UserRedisInfo.addKouShuiFanXianForRent(m_pIUserItem[i].dwUserID,shui);
				}else{
					//机器人
					this.addEatRobotScore(shui);
				}
			}
			// 定义变量
			CMD_S_GameEnd GameEnd = new CMD_S_GameEnd();

			// 剩余扑克
			int bCardPos = 0;
			for (int i = 0; i < Constants.DDZ_PLAYER; i++) {
				GameEnd.bCardCount[i] = m_bCardCount[i];
				Constants.CopyMemory(GameEnd.bCardData,bCardPos, m_bHandCardData[i], m_bCardCount[i]);
				bCardPos += m_bCardCount[i];
			}
			// 炸弹限制
			m_wBombTime = Constants.__min(m_wBombTime, 1600);

			// 最少赔率
			for (int i = 0; i < Constants.DDZ_PLAYER; i++) {
				m_bScoreTimes[i] = Constants.__max(m_bScoreTimes[i], 1);
			}
			if(m_jiesuanMode == 0){				
				//赢家结算
				for (int i = 0; i < Constants.DDZ_PLAYER; i++) {
					lScore = 0;
					if(i == winSeat){
						lScore = m_bombArray[winSeat];

						lScore *= m_doubleDiFen;
						BigDecimal b1 = new BigDecimal(lScore);
						lScore = b1.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue(); 
						for(int user =0 ;user < Constants.DDZ_PLAYER; user++){
							if(user == winSeat)
								continue;
							double winScore = 0;
							if(m_bCardCount[user] == 1){
								winScore += 0;//只剩一张不出分
							}else if(m_bCardCount[user] == 16){
								winScore += m_bCardCount[user] * 2;
								guanmen[i] = 1;
								m_vecGuanMenCount[i]++;
							}else{
								winScore += m_bCardCount[user] * 1;
								guanmen[i] = 0;
							}

							winScore *= m_doubleDiFen;
							BigDecimal b = new BigDecimal(winScore);
							winScore = b.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue(); 
							SecShmUser xianUser = dthall.getInstance().getSecurityUserInfo(m_pIUserItem[user].dwUserID);
							if(winScore > xianUser.getRmb1v1(0))
								winScore = xianUser.getRmb1v1(0);
							lScore += winScore;
						}
						SecShmUser xianUser = dthall.getInstance().getSecurityUserInfo(m_pIUserItem[i].dwUserID);
						xianUser.getRmb1v1(lScore);

						UserRmbChange.handleRmbChangeWinLose(xianUser,lScore,UserRmbChange.reason25);
						if(m_pIUserItem[i].isAndroidUser == 2){
							//robot win & lost
							this.addRobotWinScore(lScore);
						}
						if(lScore > GoldMgr.getInstance().getRmbBroadCastLimit()){
							//大于进行广播
							net.sf.json.JSONObject broad = new net.sf.json.JSONObject();
							broad.put("command","public_logic_broad_user");
							broad.put("value1", m_pIUserItem[winSeat].szNickName);
							broad.put("value2", "跑得快");
							broad.put("value3", lScore);
							broad.put("value4", "");
							AdminRedis.getInstance().pubAdminSubMsg(broad);
						}
					}else{
						lScore = m_bombArray[i];
						
						if(m_bCardCount[i] == 1){
							lScore -= 0;
						}else if(m_bCardCount[i] == 16){
							lScore -= m_bCardCount[i] * 2;
							guanmen[i] = 1;
						}else{
							lScore -= m_bCardCount[i] * 1;
							guanmen[i] = 0;
						}
						lScore *= m_doubleDiFen;
						BigDecimal b = new BigDecimal(lScore);
						lScore = b.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue(); 
						SecShmUser xianUser = dthall.getInstance().getSecurityUserInfo(m_pIUserItem[i].dwUserID);
						if(lScore < 0 && Math.abs(lScore) > xianUser.getRmb1v1(0)){
							lScore = -Math.abs(xianUser.getRmb1v1(0));
						}
						xianUser.getRmb1v1(lScore);

						UserRmbChange.handleRmbChangeWinLose(xianUser,lScore,UserRmbChange.reason25);
						if(m_pIUserItem[i].isAndroidUser == 2){
							//robot win & lost
							this.addRobotWinScore(lScore);
						}
					}
					if(lScore > 0){
						m_vecWinCount[i]++;
					}
					//记录
					m_pIUserItem[i].lUserRmb += lScore;
					GameEnd.lGameScore[i] = lScore;
					m_doubleVecResultScore[i] += lScore;
				}
			}else{
				//两两结算
				for (int i = 0; i < Constants.DDZ_PLAYER; i++) {
					lScore = 0;
					if(i == winSeat){
						lScore = m_bombArray[winSeat];

						lScore *= m_doubleDiFen;
						BigDecimal b1 = new BigDecimal(lScore);
						lScore = b1.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue(); 
						for(int user =0 ;user < Constants.DDZ_PLAYER; user++){
							if(user == winSeat)
								continue;
							double winScore = 0;
							if(m_bCardCount[user] == 1){
								winScore += 0;//只剩一张不出分的
							}else if(m_bCardCount[user] == 16){
								winScore += m_bCardCount[user] * 2;
								guanmen[i] = 1;
								m_vecGuanMenCount[i]++;
							}else{
								winScore += m_bCardCount[user] * 1;
								guanmen[i] = 0;
							}

							winScore *= m_doubleDiFen;
							BigDecimal b = new BigDecimal(winScore);
							winScore = b.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue(); 
							SecShmUser xianUser = dthall.getInstance().getSecurityUserInfo(m_pIUserItem[user].dwUserID);
							if(winScore > xianUser.getCoin(0))
								winScore = xianUser.getCoin(0);
							lScore += winScore;
						}

						SecShmUser xianUser = dthall.getInstance().getSecurityUserInfo(m_pIUserItem[i].dwUserID);
						xianUser.getRmb1v1(lScore);

						UserRmbChange.handleRmbChangeWinLose(xianUser,lScore,UserRmbChange.reason25);
						if(m_pIUserItem[i].isAndroidUser == 2){
							//robot win & lost
							this.addRobotWinScore(lScore);
						}
						if(lScore > GoldMgr.getInstance().getRmbBroadCastLimit()){
							//大于进行广播
							net.sf.json.JSONObject broad = new net.sf.json.JSONObject();
							broad.put("command","public_logic_broad_user");
							broad.put("value1", m_pIUserItem[winSeat].szNickName);
							broad.put("value2", "跑得快");
							broad.put("value3", lScore);
							broad.put("value4", "");
							AdminRedis.getInstance().pubAdminSubMsg(broad);
						}
					}else{
						lScore = m_bombArray[i];
						
						if(m_bCardCount[i] == 1){
							lScore -= 0;
						}else if(m_bCardCount[i] == 16){
							lScore -= m_bCardCount[i] * 2;
							guanmen[i] = 1;
						}else{
							lScore -= m_bCardCount[i] * 1;
							guanmen[i] = 0;
						}
						SecShmUser otherUser = null;
						for(int lindex = 0;lindex < Constants.DDZ_PLAYER;lindex++){
							if(lindex == winSeat || lindex == i){
								continue;
							}
							otherUser = dthall.getInstance().getSecurityUserInfo(m_pIUserItem[lindex].dwUserID);
							int mycard = m_bCardCount[i];
							int othercard = m_bCardCount[lindex];
							if(mycard == 1){
								mycard = 0;
							}
							if(othercard == 1)
								othercard = 0;
							if(mycard == 16)
								mycard *= 2;
							if(othercard == 16)
								othercard *= 2;
							lScore += (othercard - mycard);
						}
						lScore *= m_doubleDiFen;
						BigDecimal b = new BigDecimal(lScore);
						lScore = b.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue(); 
						SecShmUser xianUser = dthall.getInstance().getSecurityUserInfo(m_pIUserItem[i].dwUserID);
						if(lScore < 0 && Math.abs(lScore) > xianUser.getCoin(0)){
							lScore = -Math.abs(xianUser.getCoin(0));
						}else if(lScore > 0 && otherUser != null && lScore > otherUser.getCoin(0)){
							lScore = otherUser.getCoin(0);
						}
						xianUser.getRmb1v1(lScore);

						UserRmbChange.handleRmbChangeWinLose(xianUser,lScore,UserRmbChange.reason25);
						if(m_pIUserItem[i].isAndroidUser == 2){
							//robot win & lost
							this.addRobotWinScore(lScore);
						}
					}
					if(lScore > 0){
						m_vecWinCount[i]++;
					}
					//记录
					m_pIUserItem[i].lUserRmb += lScore;
					GameEnd.lGameScore[i] = lScore;
					m_doubleVecResultScore[i] += lScore;
				}
			}
			//扣赢的
			if(this.inHall() && m_dwcKouYing != 0 && m_dwcKouYingRate > 0){
				for(int i = 0;i < 3;i++){
					//不区别机器人还是真人
					//只扣赢家的，输家输的不变
					if(GameEnd.lGameScore[i] > 0){
						double kou = GameEnd.lGameScore[i] * m_dwcKouYingRate;
						BigDecimal b = new BigDecimal(kou);
						kou = b.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
						SecShmUser xianUser = dthall.getInstance().getSecurityUserInfo(m_pIUserItem[i].dwUserID);
						//再次扣除需要
						xianUser.getRmb1v1(0 - kou);
						m_pIUserItem[i].lUserRmb -= kou;
						GameEnd.lGameScore[i] -= kou;
						m_doubleVecResultScore[i] -= kou;
						UserRmbChange.handleRmbChangeWinLose(xianUser,0 - kou, UserRmbChange.reason25);
						if(m_pIUserItem[i].isAndroidUser == 0){
							//只记录真人的
							UserRedisInfo.addKouYingFanXianForRent(m_pIUserItem[i].dwUserID,kou);
							double givesys = (1.0 - m_dwcKouYingFanliRate) * kou;
							double giveagent = m_dwcKouYingFanliRate * kou;
							BigDecimal b1 = new BigDecimal(givesys);
							givesys = b1.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
							BigDecimal b2 = new BigDecimal(giveagent);
							giveagent = b2.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
							UserRedisInfo.addKouYingFanXian(m_pIUserItem[i].dwUserID, giveagent);
							DwcRedisRecord.getInstance().addRmbGameInfo(UserRmbChange.reason25, givesys);
						}
					}
				}
			}
			boolean isYeJi = true;
			if(this.inUserClub()){
				for(int i = 0;i < 3;i++){
					m_doubleKouWinResultScore[i] += GameEnd.lGameScore[i];
				}
				this.m_kouWinCurrJu++;
				if(this.m_kouWinSumJu == this.m_kouWinCurrJu){
					//扣除业绩
					for(int i = 0;i < 3;i++){
						if (m_pIUserItem[i].dwUserID <= 0 || Constants.US_LOOKON == m_pIUserItem[i].cbUserStatus) {
							continue;
						}
						//只扣赢家的，输家输的不变
						if(m_doubleKouWinResultScore[i] > 0){
							double kou = m_doubleKouWinResultScore[i] * m_dwcKouYingRate;
							BigDecimal b = new BigDecimal(kou);
							kou = b.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
							m_doubleVecResultScore[i] -= kou;

							SecShmUser safeuser = dthall.getInstance().getSecurityUserInfo(m_pIUserItem[i].dwUserID);
							m_pIUserItem[i].lUserRmb -= kou;
							safeuser.getRmb1v1(0 - kou);
							
							if(m_pIUserItem[i].isAndroidUser == 0){
								//只记录真人的
								UserRedisInfo.addKouYingFanXianForRent(m_pIUserItem[i].dwUserID,kou);
								double givesys = (1.0 - m_dwcKouYingFanliRate) * kou;
								double giveagent = m_dwcKouYingFanliRate * kou;
								BigDecimal b1 = new BigDecimal(givesys);
								givesys = b1.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
								BigDecimal b2 = new BigDecimal(giveagent);
								giveagent = b2.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
								UserRedisInfo.addKouYingFanXian(m_pIUserItem[i].dwUserID, giveagent);
								DwcRedisRecord.getInstance().addRmbGameInfo(UserRmbChange.reason18, givesys);
							}
						}
					}
					this.m_kouWinCurrJu = 0;
					for(int i = 0;i < 3;i++){
						if (m_pIUserItem[i].dwUserID <= 0 || Constants.US_LOOKON == m_pIUserItem[i].cbUserStatus) {
							continue;
						}
						m_doubleKouWinResultScore[i] = 0.0;
					}
				}else{
					isYeJi = false;
				}
			}
			if(hasAutoDianKong()){
				int dianKongUid = getDianKongUid();
				int seat = FindSeat(dianKongUid);
				if(seat != Constants.INVALID_CHAIR){
					checkDianKong(m_doubleVecResultScore[seat]);
				}
			}
			SUBCMD_S_JieSuan cmd = new SUBCMD_S_JieSuan();
			cmd.nUserScore = m_vecResultScore;
			cmd.lWinSeat = winSeat;
			cmd.lShuiShou = realshui;
			for(int i = 0;i <Constants.DDZ_PLAYER; i++) {
				cmd.lUserCoin[i] = m_pIUserItem[i].lUserRmb;
				cmd.lWonLose[i] = GameEnd.lGameScore[i];
			}
			//加入业绩
			for(int i = 0;i < 3;i++){
				if(m_pIUserItem[i].isAndroidUser == 0 && isYeJi){
					//只处理机器人,正负都处理
					UserRedisInfo.addYeJiFanXian(m_pIUserItem[i].dwUserID,Math.abs(GameEnd.lGameScore[i]),m_clubOwnerId);
				}
			}
			SendData(Constants.INVALID_CHAIR, cmd.getJsonData());
			
			// 玩家积分和赢了多少话费豆
			for (int i = 0; i < Constants.DDZ_PLAYER; i++) {
				if (m_pIUserItem[i] != null) {
					tagUserData pUserData = m_pIUserItem[i].GetUserData();
					GameEnd.dwUserID[i] = pUserData.dwUserID;
					GameEnd.m_bombCountArray[i] = m_boomCountArray[i];
					GameEnd.bGuanmen[i] = guanmen[i];
					GameEnd.allScoreArray[i] = m_doubleVecResultScore[i];				
				}
			}

			String sData = GameEnd.getJsonData();
			// 发送信息
			SendTableData(Constants.INVALID_CHAIR, Constants.SUB_S_GAME_END, GameEnd, 0, sData);

			// 切换用户
			m_wFirstUser = wChairID;

			// 结束游戏
			ConcludeGame();

		}
		if (m_byRound <= 1 && cbReason == Constants.GAME_END_DISMISS) {
			
			// 发送信息
			CMD_S_GameEnd GameEnd = new CMD_S_GameEnd();
			// 玩家积分和赢了多少话费豆
			for (int i = 0; i < Constants.DDZ_PLAYER; i++) {
				if (m_pIUserItem[i] != null) {
					tagUserData pUserData = m_pIUserItem[i].GetUserData();
					GameEnd.dwUserID[i] = pUserData.dwUserID;
			
				}
			}

			String sData = GameEnd.getJsonData();			
			SendTableData(Constants.INVALID_CHAIR, Constants.SUB_S_GAME_DISMISS, GameEnd, 0, sData);
			ConcludeGame();
			
			SUBCMD_S_DismissRoom cmd = new SUBCMD_S_DismissRoom();
			cmd.lUid = 0;
			cmd.cbResult = 0;
			cmd.m_wUserChairID = 0;
			cmd.m_dwTableID = m_dwTableID;

			SendData(Constants.INVALID_CHAIR, cmd.getJsonData());
			
	
			DelayRemove();
			beforeDestroy(cloneServerPdkUserPack(m_pIUserItem),null,m_doubleVecResultScore);
			QpGameMgr.getInstance().OnDismissRoom(this);
			
		}else if (m_byRound > m_byMaxRound || cbReason == Constants.GAME_END_DISMISS){		
			if(m_byRound > m_byMaxRound){
				for(int i = 0;i < 3;i++){
					SHMUser user = dthall.getInstance().getUserInfo(m_pIUserItem[i].dwUserID);
					if(user != null){
						user.getDwcJuShu(1);
					}
				}
			}
			SUBCMD_S_REPORT cmd = new SUBCMD_S_REPORT();
			cmd.cbReason = cbReason;
			cmd.whoDismiss = 0;

			for (int k = 0; k < 3; k++) {
				cmd.vecWinScore[k] = m_vecWinScore[k];
				cmd.vecLoseScore[k] = m_vecLoseScore[k];
				cmd.vecResultScore[k] = m_doubleVecResultScore[k];
				cmd.vecWinCount[k] = m_vecWinCount[k];
				cmd.vecBombCount[k] = m_vecBombCount[k];
				cmd.vecGuanMenCount[k] = m_vecGuanMenCount[k];
			}

			SendData(Constants.INVALID_CHAIR, cmd.getJsonData());

			DelayRemove();
			ConcludeGame();

			beforeDestroy(cloneServerPdkUserPack(m_pIUserItem),null,m_doubleVecResultScore);
			QpGameMgr.getInstance().OnDismissRoom(this);

		}

		return false;
	}
	boolean onEventGameEndGold(int wChairID, ServerUserItem pIServerUserItem, int cbReason) {		
		m_byRound = m_byRound + 1;
		OnRoundInfoChange();
		
		if(cbReason == Constants.GER_NORMAL){
			// 游戏积分
			int lScore = 0;
			int winSeat = 0;
			int guanmen[] = new int[3];
			for(int i = 0; i < Constants.DDZ_PLAYER; i++){
				if(m_bCardCount[i] == 0){
					winSeat = i;
				}
			}
			double shuishourate = getShuiShou(this.GetType());
			double realshui[] = new double[3];
			for(int i = 0;i < 3;i++){
				realshui[i] = 0;
			}
			int shui = (int) (this.m_difen * shuishourate);

			//扣税
			for(int i = 0;i < 3;i++){
				if (m_pIUserItem[i].dwUserID <= 0 || Constants.US_LOOKON == m_pIUserItem[i].cbUserStatus) {
					continue;
				}
				if(m_kouShuiMode.equals("win") && i != winSeat)
					continue;
				else if(m_kouShuiMode.equals("lose") && i == winSeat)
					continue;
				realshui[i] = shui;
				
				SecShmUser user = dthall.getInstance().getSecurityUserInfo(m_pIUserItem[i].dwUserID);
				//扣除税收先,在扣除UU逗的时候，最多扣完,不会扣成负数(系统不补贴)
				m_pIUserItem[i].lUserCoin -= shui;
				user.getCoin(0 - shui);
				if(m_pIUserItem[i].isAndroidUser == 0){
					UserGoldChange.handleGoldChangeKouShui(user, shui, UserGoldChange.reason22);
					this.addEatNormalScore(shui);
					handleGoldGiveBack(m_pIUserItem[i].dwUserID,shui);
				}else{
					//机器人
					this.addEatRobotScore(shui);
				}
			}
			// 定义变量
			CMD_S_GameEnd GameEnd = new CMD_S_GameEnd();

			// 剩余扑克
			int bCardPos = 0;
			for (int i = 0; i < Constants.DDZ_PLAYER; i++) {
				GameEnd.bCardCount[i] = m_bCardCount[i];
				Constants.CopyMemory(GameEnd.bCardData,bCardPos, m_bHandCardData[i], m_bCardCount[i]);
				bCardPos += m_bCardCount[i];
			}
			// 炸弹限制
			m_wBombTime = Constants.__min(m_wBombTime, 1600);

			// 最少赔率
			for (int i = 0; i < Constants.DDZ_PLAYER; i++) {
				m_bScoreTimes[i] = Constants.__max(m_bScoreTimes[i], 1);
			}
			if(m_jiesuanMode == 0){				
				//赢家结算
				for (int i = 0; i < Constants.DDZ_PLAYER; i++) {
					lScore = 0;
					if(i == winSeat){
						lScore = m_bombArray[winSeat];
						lScore *= m_difen;
						for(int user =0 ;user < Constants.DDZ_PLAYER; user++){
							if(user == winSeat)
								continue;
							int winScore = 0;
							if(m_bCardCount[user] == 1){
								winScore += 0;//只剩一张不出分
							}else if(m_bCardCount[user] == 16){
								winScore += m_bCardCount[user] * 2;
								guanmen[i] = 1;
								m_vecGuanMenCount[i]++;
							}else{
								winScore += m_bCardCount[user] * 1;
								guanmen[i] = 0;
							}

							winScore *= m_difen;
							SecShmUser xianUser = dthall.getInstance().getSecurityUserInfo(m_pIUserItem[user].dwUserID);
							if(winScore > xianUser.getCoin(0))
								winScore = xianUser.getCoin(0);
							lScore += winScore;
						}
						SecShmUser xianUser = dthall.getInstance().getSecurityUserInfo(m_pIUserItem[i].dwUserID);
						xianUser.getCoin(lScore);

						UserGoldChange.handleGoldChangeWinLose(xianUser,lScore,UserGoldChange.reason25);
						if(m_pIUserItem[i].isAndroidUser == 2){
							//robot win & lost
							this.addRobotWinScore(lScore);
						}
					}else{
						lScore = m_bombArray[i];
						
						if(m_bCardCount[i] == 1){
							lScore -= 0;
						}else if(m_bCardCount[i] == 16){
							lScore -= m_bCardCount[i] * 2;
							guanmen[i] = 1;
						}else{
							lScore -= m_bCardCount[i] * 1;
							guanmen[i] = 0;
						}
						lScore *= m_difen;
						SecShmUser xianUser = dthall.getInstance().getSecurityUserInfo(m_pIUserItem[i].dwUserID);
						if(lScore < 0 && Math.abs(lScore) > xianUser.getCoin(0)){
							lScore = -Math.abs(xianUser.getCoin(0));
						}
						xianUser.getCoin(lScore);

						UserGoldChange.handleGoldChangeWinLose(xianUser,lScore,UserGoldChange.reason25);
						if(m_pIUserItem[i].isAndroidUser == 2){
							//robot win & lost
							this.addRobotWinScore(lScore);
						}
					}
					if(lScore > 0){
						m_vecWinCount[i]++;
					}
					//记录
					m_pIUserItem[i].lUserCoin += lScore;
					GameEnd.lGameScore[i] = lScore;
					m_vecResultScore[i] += lScore;
				}
			}else{
				//两两结算
				for (int i = 0; i < Constants.DDZ_PLAYER; i++) {
					lScore = 0;
					if(i == winSeat){
						lScore = m_bombArray[winSeat];
						lScore *= m_difen;
						for(int user =0 ;user < Constants.DDZ_PLAYER; user++){
							if(user == winSeat)
								continue;
							int winScore = 0;
							if(m_bCardCount[user] == 1){
								winScore += 0;//只剩一张不出分的
							}else if(m_bCardCount[user] == 16){
								winScore += m_bCardCount[user] * 2;
								guanmen[i] = 1;
								m_vecGuanMenCount[i]++;
							}else{
								winScore += m_bCardCount[user] * 1;
								guanmen[i] = 0;
							}

							winScore *= m_difen;
							SecShmUser xianUser = dthall.getInstance().getSecurityUserInfo(m_pIUserItem[user].dwUserID);
							if(winScore > xianUser.getCoin(0))
								winScore = xianUser.getCoin(0);
							lScore += winScore;
						}

						SecShmUser xianUser = dthall.getInstance().getSecurityUserInfo(m_pIUserItem[i].dwUserID);
						xianUser.getCoin(lScore);

						UserGoldChange.handleGoldChangeWinLose(xianUser,lScore,UserGoldChange.reason25);
						if(m_pIUserItem[i].isAndroidUser == 2){
							//robot win & lost
							this.addRobotWinScore(lScore);
						}
					}else{
						lScore = m_bombArray[i];
						
						if(m_bCardCount[i] == 1){
							lScore -= 0;
						}else if(m_bCardCount[i] == 16){
							lScore -= m_bCardCount[i] * 2;
							guanmen[i] = 1;
						}else{
							lScore -= m_bCardCount[i] * 1;
							guanmen[i] = 0;
						}
						SecShmUser otherUser = null;
						for(int lindex = 0;lindex < Constants.DDZ_PLAYER;lindex++){
							if(lindex == winSeat || lindex == i){
								continue;
							}
							otherUser = dthall.getInstance().getSecurityUserInfo(m_pIUserItem[lindex].dwUserID);
							int mycard = m_bCardCount[i];
							int othercard = m_bCardCount[lindex];
							if(mycard == 1){
								mycard = 0;
							}
							if(othercard == 1)
								othercard = 0;
							if(mycard == 16)
								mycard *= 2;
							if(othercard == 16)
								othercard *= 2;
							lScore += (othercard - mycard);
						}
						lScore *= m_difen;
						SecShmUser xianUser = dthall.getInstance().getSecurityUserInfo(m_pIUserItem[i].dwUserID);
						if(lScore < 0 && Math.abs(lScore) > xianUser.getCoin(0)){
							lScore = -Math.abs(xianUser.getCoin(0));
						}else if(lScore > 0 && otherUser != null && lScore > otherUser.getCoin(0)){
							lScore = otherUser.getCoin(0);
						}
						xianUser.getCoin(lScore);

						UserGoldChange.handleGoldChangeWinLose(xianUser,lScore,UserGoldChange.reason25);
						if(m_pIUserItem[i].isAndroidUser == 2){
							//robot win & lost
							this.addRobotWinScore(lScore);
						}
					}
					if(lScore > 0){
						m_vecWinCount[i]++;
					}
					//记录
					m_pIUserItem[i].lUserCoin += lScore;
					GameEnd.lGameScore[i] = lScore;
					m_vecResultScore[i] += lScore;
				}
			}
			
			SUBCMD_S_JieSuan cmd = new SUBCMD_S_JieSuan();
			cmd.nUserScore = m_vecResultScore;
			cmd.lWinSeat = winSeat;
			cmd.lShuiShou = realshui;
			for(int i = 0;i <Constants.DDZ_PLAYER; i++) {
				cmd.lUserCoin[i] = m_pIUserItem[i].lUserCoin;
			}
			SendData(Constants.INVALID_CHAIR, cmd.getJsonData());
			
			// 玩家积分和赢了多少话费豆
			for (int i = 0; i < Constants.DDZ_PLAYER; i++) {
				if (m_pIUserItem[i] != null) {
					tagUserData pUserData = m_pIUserItem[i].GetUserData();
					GameEnd.dwUserID[i] = pUserData.dwUserID;
					GameEnd.m_bombCountArray[i] = m_boomCountArray[i];
					GameEnd.bGuanmen[i] = guanmen[i];
					GameEnd.allScoreArray[i] = m_vecResultScore[i];				
				}
			}

			String sData = GameEnd.getJsonData();
			// 发送信息
			SendTableData(Constants.INVALID_CHAIR, Constants.SUB_S_GAME_END, GameEnd, 0, sData);

			// 切换用户
			m_wFirstUser = wChairID;

			// 结束游戏
			ConcludeGame();

		}
		if (m_byRound <= 1 && cbReason == Constants.GAME_END_DISMISS) {
			
			// 发送信息
			CMD_S_GameEnd GameEnd = new CMD_S_GameEnd();
			// 玩家积分和赢了多少话费豆
			for (int i = 0; i < Constants.DDZ_PLAYER; i++) {
				if (m_pIUserItem[i] != null) {
					tagUserData pUserData = m_pIUserItem[i].GetUserData();
					GameEnd.dwUserID[i] = pUserData.dwUserID;
			
				}
			}

			String sData = GameEnd.getJsonData();			
			SendTableData(Constants.INVALID_CHAIR, Constants.SUB_S_GAME_DISMISS, GameEnd, 0, sData);
			ConcludeGame();
			
			SUBCMD_S_DismissRoom cmd = new SUBCMD_S_DismissRoom();
			cmd.lUid = 0;
			cmd.cbResult = 0;
			cmd.m_wUserChairID = 0;
			cmd.m_dwTableID = m_dwTableID;

			SendData(Constants.INVALID_CHAIR, cmd.getJsonData());
			
	
			DelayRemove();
			beforeDestroy(cloneServerPdkUserPack(m_pIUserItem),m_vecResultScore,null);
			QpGameMgr.getInstance().OnDismissRoom(this);
			
		}else if (m_byRound > m_byMaxRound || cbReason == Constants.GAME_END_DISMISS){		
			if(m_byRound > m_byMaxRound){
				for(int i = 0;i < 3;i++){
					SHMUser user = dthall.getInstance().getUserInfo(m_pIUserItem[i].dwUserID);
					if(user != null){
						user.getGoldJuShu(1);
					}
				}
			}
			SUBCMD_S_REPORT cmd = new SUBCMD_S_REPORT();
			cmd.cbReason = cbReason;
			cmd.whoDismiss = 0;

			for (int k = 0; k < 3; k++) {
				cmd.vecWinScore[k] = m_vecWinScore[k];
				cmd.vecLoseScore[k] = m_vecLoseScore[k];
				cmd.vecResultScore[k] = m_vecResultScore[k];
				cmd.vecWinCount[k] = m_vecWinCount[k];
				cmd.vecBombCount[k] = m_vecBombCount[k];
				cmd.vecGuanMenCount[k] = m_vecGuanMenCount[k];
			}

			SendData(Constants.INVALID_CHAIR, cmd.getJsonData());

			DelayRemove();
			ConcludeGame();

			beforeDestroy(cloneServerPdkUserPack(m_pIUserItem),m_vecResultScore,null);
			QpGameMgr.getInstance().OnDismissRoom(this);

		}

		return false;
	}
	boolean OnEventGameEndZuJu(int wChairID, ServerUserItem pIServerUserItem, int cbReason) {
		
		m_byRound = m_byRound + 1;
		OnRoundInfoChange();
		
		if(cbReason == Constants.GER_NORMAL){
			// 定义变量
			CMD_S_GameEnd GameEnd = new CMD_S_GameEnd();

			// 剩余扑克
			int bCardPos = 0;
			for (int i = 0; i < Constants.DDZ_PLAYER; i++) {
				GameEnd.bCardCount[i] = m_bCardCount[i];
				Constants.CopyMemory(GameEnd.bCardData,bCardPos, m_bHandCardData[i], m_bCardCount[i]);
				bCardPos += m_bCardCount[i];
			}
			// 炸弹限制
			m_wBombTime = Constants.__min(m_wBombTime, 1600);

			// 最少赔率
			for (int i = 0; i < Constants.DDZ_PLAYER; i++) {
				m_bScoreTimes[i] = Constants.__max(m_bScoreTimes[i], 1);
			}

			// 游戏积分
			int lScore = 0;
			int winSeat = 0;
			int guanmen[] = new int[3];
			for(int i = 0; i < Constants.DDZ_PLAYER; i++){
				if(m_bCardCount[i] == 0){
					winSeat = i;
				}
			}
			if(m_jiesuanMode == 0){				
				//赢家结算
				for (int i = 0; i < Constants.DDZ_PLAYER; i++) {
					lScore = 0;
					if(i == winSeat){
						lScore = m_bombArray[winSeat];
						for(int user =0 ;user < Constants.DDZ_PLAYER; user++){
							if(m_bCardCount[user] == 1){
								lScore += 0;//只剩一张不出分
							}else if(m_bCardCount[user] == 16){
								lScore += m_bCardCount[user] * 2;
								guanmen[i] = 1;
								m_vecGuanMenCount[i]++;
							}else{
								lScore += m_bCardCount[user] * 1;
								guanmen[i] = 0;
							}
						}
					}else{
						lScore = m_bombArray[i];
						
						if(m_bCardCount[i] == 1){
							lScore -= 0;
						}else if(m_bCardCount[i] == 16){
							lScore -= m_bCardCount[i] * 2;
							guanmen[i] = 1;
						}else{
							lScore -= m_bCardCount[i] * 1;
							guanmen[i] = 0;
						}
					}
					GameEnd.lGameScore[i] = lScore;
					m_vecResultScore[i] += lScore;
					if(lScore > 0){
						m_vecWinCount[i]++;
					}
				}
			}else{
				//两两结算
				for (int i = 0; i < Constants.DDZ_PLAYER; i++) {
					lScore = 0;
					if(i == winSeat){
						lScore = m_bombArray[winSeat];
						for(int user =0 ;user < Constants.DDZ_PLAYER; user++){
							if(m_bCardCount[user] == 1){
								lScore += 0;//只剩一张不出分的
							}else if(m_bCardCount[user] == 16){
								lScore += m_bCardCount[user] * 2;
								guanmen[i] = 1;
								m_vecGuanMenCount[i]++;
							}else{
								lScore += m_bCardCount[user] * 1;
								guanmen[i] = 0;
							}
						}
					}else{
						lScore = m_bombArray[i];
						
						if(m_bCardCount[i] == 1){
							lScore -= 0;
						}else if(m_bCardCount[i] == 16){
							lScore -= m_bCardCount[i] * 2;
							guanmen[i] = 1;
						}else{
							lScore -= m_bCardCount[i] * 1;
							guanmen[i] = 0;
						}
						for(int lindex = 0;lindex < Constants.DDZ_PLAYER;lindex++){
							if(lindex == winSeat || lindex == i){
								continue;
							}
							int mycard = m_bCardCount[i];
							int othercard = m_bCardCount[lindex];
							if(mycard == 1){
								mycard = 0;
							}
							if(othercard == 1)
								othercard = 0;
							if(mycard == 16)
								mycard *= 2;
							if(othercard == 16)
								othercard *= 2;
							lScore += (othercard - mycard);
						}
					}
					GameEnd.lGameScore[i] = lScore;
					m_vecResultScore[i] += lScore;
					if(lScore > 0){
						m_vecWinCount[i]++;
					}
				}
			}
			
			SUBCMD_S_JieSuan cmd = new SUBCMD_S_JieSuan();
			cmd.nUserScore = m_vecResultScore;
			SendData(Constants.INVALID_CHAIR, cmd.getJsonData());
			
			// 玩家积分和赢了多少话费豆
			for (int i = 0; i < Constants.DDZ_PLAYER; i++) {
				if (m_pIUserItem[i] != null) {
					tagUserData pUserData = m_pIUserItem[i].GetUserData();
					GameEnd.dwUserID[i] = pUserData.dwUserID;
					GameEnd.m_bombCountArray[i] = m_boomCountArray[i];
					GameEnd.bGuanmen[i] = guanmen[i];
					GameEnd.allScoreArray[i] = m_vecResultScore[i];				
				}
			}

			String sData = GameEnd.getJsonData();
			// 发送信息
			SendTableData(Constants.INVALID_CHAIR, Constants.SUB_S_GAME_END, GameEnd, 0, sData);

			// 切换用户
			m_wFirstUser = wChairID;

			// 结束游戏
			ConcludeGame();

		}
		if (m_byRound <= 1 && cbReason == Constants.GAME_END_DISMISS) {
			
			// 发送信息
			CMD_S_GameEnd GameEnd = new CMD_S_GameEnd();
			// 玩家积分和赢了多少话费豆
			for (int i = 0; i < Constants.DDZ_PLAYER; i++) {
				if (m_pIUserItem[i] != null) {
					tagUserData pUserData = m_pIUserItem[i].GetUserData();
					GameEnd.dwUserID[i] = pUserData.dwUserID;
			
				}
			}

			String sData = GameEnd.getJsonData();			
			SendTableData(Constants.INVALID_CHAIR, Constants.SUB_S_GAME_DISMISS, GameEnd, 0, sData);
			ConcludeGame();
			
			SUBCMD_S_DismissRoom cmd = new SUBCMD_S_DismissRoom();
			cmd.lUid = 0;
			cmd.cbResult = 0;
			cmd.m_wUserChairID = 0;
			cmd.m_dwTableID = m_dwTableID;

			SendData(Constants.INVALID_CHAIR, cmd.getJsonData());
			
	
			DelayRemove();
			
			QpGameMgr.getInstance().OnDismissRoom(this);
			
		}else if (m_byRound > m_byMaxRound || cbReason == Constants.GAME_END_DISMISS){
			if(m_byRound > m_byMaxRound){
				for(int i = 0;i < 3;i++){
					SHMUser user = dthall.getInstance().getUserInfo(m_pIUserItem[i].dwUserID);
					if(user != null){
						user.getZuJuJuShu(1);
					}
				}
			}
		
			int before_cost[] = new int[3];
			int after_cost[] = new int[3];

			int cost[] = new int[3];			
			for(int i=0;i<3;i++)
			{
				before_cost[i] = 0;
				cost[i] = 0;
				after_cost[i] = 0;
			}
			
			for (int i = 0; i < 3; i++) 
			{				
				if(m_pIUserItem[i].dwUserID > 0)
				{
					SHMUser user = dthall.getInstance().getUserInfo(m_pIUserItem[i].dwUserID);
					if(user != null)
					{
						before_cost[i] = user.getGem(0);
					}
				}
			}			
			int minRound = 1;
			if(m_byMaxRound > 8)
			{
				minRound = 4;
			}			
			if (m_byRound > minRound) {

				if (m_payWay.equalsIgnoreCase("FZPAY")) {
					int cost_gem = 0;
					for (int i = 0; i < 3; i++) {
						if (m_pIUserItem[i].dwUserID > 0) {
							cost_gem += m_byCostGem;
						}
					}					
					if (m_Creator > 0) {
						SHMUser user = dthall.getInstance().getUserInfo(m_Creator);
						if (user != null) {
							user.getGem(0 - cost_gem);
						}
					} else {
						SHMUser user = dthall.getInstance().getUserInfo(m_pIUserItem[0].dwUserID);
						if (user != null) {
							user.getGem(0 - cost_gem);
						}
						cost[0] = 0 - cost_gem;
					}
				}
				if (m_payWay.equalsIgnoreCase("AAPAY")) {
					for (int i = 0; i < 3; i++) {
						if (m_pIUserItem[i].dwUserID > 0) {
							SHMUser user = dthall.getInstance().getUserInfo(m_pIUserItem[i].dwUserID);
							if (user != null) {
								user.getGem(0 - m_byCostGem);
								cost[i] = 0 - m_byCostGem;
							}
						}
					}
				}
				if (m_payWay == "WINPAY") {
					if (m_payWay.equalsIgnoreCase("WINPAY")) {
						int maxUser = 3;
						int activeUser = 0;
						for(int i = 0;i < maxUser;i++){
							if (m_pIUserItem[i].dwUserID > 0){
								activeUser++;
							}
						}
						int maxcost = m_byCostGem * activeUser;
						List<Integer> winuser = new ArrayList<Integer>();
						int max = -1;
						for (int i = 0; i < maxUser; i++) {
							if (m_vecResultScore[i] > max) {
								max = m_vecResultScore[i];
							}
						}
						for (int i = 0; i < maxUser; i++) {
							if (m_vecResultScore[i] == max) {
								winuser.add(i);
							}
						}
						float rate = m_byRound * 1.0f / m_byMaxRound;
						if(rate > 1.0) rate = 1.0f;
						rate *= maxcost;
						Float frate = new Float(rate);
						int cost_gem = frate.intValue();
						cost_gem /= winuser.size();

						for (int i = 0; i < maxUser; i++) {
							if (m_pIUserItem[i].dwUserID > 0 && winuser.indexOf(i) != -1) {
								SHMUser user = dthall.getInstance().getUserInfo(m_pIUserItem[i].dwUserID);
								if (user != null) {
									user.getGem(0 - cost_gem);
									cost[i] = 0 - cost_gem;
								}
							}
						}
					}		
				}
				if(m_payWay == "CLUBPAY"){
					int cost_gem = m_byCostGem;
					DbInfoMgr.getInstance().costClubOwnerGem(this.m_clubOwnerId,cost_gem);
				}
				for (int i = 0; i < 3; i++) 
				{				
					if(m_pIUserItem[i].dwUserID > 0)
					{
						SHMUser user = dthall.getInstance().getUserInfo(m_pIUserItem[i].dwUserID);
						if(user != null)
						{
							after_cost[i] = user.getGem(0);
						}
					}
				}					
			}
			SUBCMD_S_REPORT cmd = new SUBCMD_S_REPORT();
			cmd.cbReason = cbReason;
			cmd.whoDismiss = 0;

			for (int k = 0; k < 3; k++) {
				cmd.vecWinScore[k] = m_vecWinScore[k];
				cmd.vecLoseScore[k] = m_vecLoseScore[k];
				cmd.vecResultScore[k] = m_vecResultScore[k];
				cmd.vecWinCount[k] = m_vecWinCount[k];
				cmd.vecBombCount[k] = m_vecBombCount[k];
				cmd.vecGuanMenCount[k] = m_vecGuanMenCount[k];
			}

			SendData(Constants.INVALID_CHAIR, cmd.getJsonData());

			log_counter++;
			log_counter = log_counter % 100;
			Long t = System.currentTimeMillis() / 1000;
			Long battle_id = (t % 1000000) * 100 + log_counter;

			SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
			String created = df.format(new Date());
			{

				JSONObject root = new JSONObject();

				root.put("command", "save_battle_log");
				root.put("battle_id", battle_id);

				root.put("room_type", GetType());

				root.put("room_id", m_dwTableID);
				root.put("creator", GetCreator());
				
				root.put("jushu", m_byMaxRound);
				root.put("limitscore", 0);
				
				if (m_payWay == "WINPAY") {
					root.put("payway", 1);	
				}else if (m_payWay == "BIGWINPAY") {
					root.put("payway", 2);
				}else if(m_payWay == "AAPAY"){
					root.put("payway", 0);
				}else{
					root.put("payway", 10);
				}
				root.put("created", created);
				root.put("uid0", (int) m_pIUserItem[0].dwUserID);
				root.put("nickname0", m_pIUserItem[0].szNickName);
				root.put("score0", m_vecResultScore[0]);
				root.put("cost0", cost[0]);
				root.put("uid1", (int) m_pIUserItem[1].dwUserID);
				root.put("nickname1", m_pIUserItem[1].szNickName);
				root.put("score1", m_vecResultScore[1]);
				root.put("cost1", cost[1]);
				root.put("uid2", (int) m_pIUserItem[2].dwUserID);
				root.put("nickname2", m_pIUserItem[2].szNickName);
				root.put("score2", m_vecResultScore[2]);
				root.put("cost2", cost[2]);
				
				root.put("headurl0", dthall.getInstance().Handle_OnGetUserAvatar(m_pIUserItem[0].dwUserID));
				root.put("headurl1", dthall.getInstance().Handle_OnGetUserAvatar(m_pIUserItem[1].dwUserID));
				root.put("headurl2", dthall.getInstance().Handle_OnGetUserAvatar(m_pIUserItem[2].dwUserID));	
				
				if(m_clubId != 0){
					//club
					root.put("clubid", m_clubId);
					root.put("wfdesc", m_wanFaStr);
					if(m_payWay == "CLUBPAY"){
						root.put("payway", 10);
					}
					ClubRedis.getInstance().addClubBattleLog(m_clubId,root.toString());
				}
				
				GameDB.getInstance().push_task(null, root);

				try
				{
					for(int i =0;i<3;i++)
					{
						if(m_pIUserItem[i].dwUserID > 0 && cost[i] != 0)
						{
							JSONObject root_cost = new JSONObject();
							root_cost.put("command", "save_charge_log");
							root_cost.put("created", created);
							root_cost.put("uid", (int) m_pIUserItem[i].dwUserID);
							root_cost.put("before_cost", (int) before_cost[i]);
							root_cost.put("after_cost", (int) after_cost[i]);
							root_cost.put("cost", (int) cost[i]);
							root_cost.put("reason", "用户" + m_pIUserItem[0].dwUserID + "创建   跑得快  " + m_byMaxRound + "局 " + m_payWay );
							root_cost.put("room_id", m_dwTableID);
							
							GameDB.getInstance().push_task(null, root_cost);
						}
					}	
				}catch(Exception e)
				{
					e.printStackTrace();
				}
			}
			if(isFreeZuJuType()){
				double[] score = new double[3];
				for(int i = 0;i < 4;i++){
					score[i] = m_vecResultScore[i];
				}
				beforeDestroy(cloneServerPdkUserPack(m_pIUserItem),null,score);
			}
			m_bTableStarted = false;
			for (int i = 0; i < 3; i++) {// 清除牌局数据
				m_vecResultScore[i] = 0;
			}

			DelayRemove();
			ConcludeGame();
			
			QpGameMgr.getInstance().OnDismissRoom(this);


			//处理积分
			if(m_byRound == m_byMaxRound){
				int score = 1;
				for(int i = 0;i < 3;i++){//三人
					if(m_pIUserItem[i].dwUserID > 0){
						int uid = m_pIUserItem[i].dwUserID;
						UserActionActivity activity = ActivityMgr.getInstance().handleSendHuaFeiActionByPlay(uid,score,"*");
						if(activity.m_useActioned){
							RankMgr.getInstance().addUserRankScore(uid,activity.m_expGet);
						}
					}
				}
			}
		}



		return false;
	}

	boolean OnGameMessage(int wSubCmdID, String[] vecArg, ServerUserItem pIServerUserItem) {
		mKXTime = 0;
		switch (wSubCmdID) {
		case Constants.SUB_C_USER_READY:// 用户准备
		{
			// 变量定义
			if (pIServerUserItem != null && !pIServerUserItem.IsAndroidUser()) {
				setBase(Constants.atoi(vecArg[0]));
				tagUserData pUserData = pIServerUserItem.GetUserData();
				for (int i = 0; i < Constants.DDZ_PLAYER; i++) {
					if (m_pIUserItem[i] != null && m_pIUserItem[i].GetUserData() != null) {
						m_pIUserItem[i].GetUserData().cbUserStatus = Constants.US_READY;
					}
				}
				TryStartGame();
				return true;
			}
		}
		case Constants.SUB_C_LAND_SCORE: // 用户叫分
		{

			// 用户效验
			tagUserData pUserData = pIServerUserItem.GetUserData();
			if (pUserData.cbUserStatus != Constants.US_PLAY)
				return true;

			// 用户效验
			// ASSERT(m_wCurrentUser == pUserData.wChairID);
			if (m_wCurrentUser != pUserData.wChairID)
				return false;

			// 消息处理
			CMD_C_LandScore pLandScore = new CMD_C_LandScore();
			// pUserData.wChairID
			if (vecArg.length > 0) {
				pLandScore.bLandScore = Constants.atoi(vecArg[0]);
			} else {
				pLandScore.bLandScore = 0;
			}

			return OnUserLandScore(pUserData.wChairID, pLandScore.bLandScore);
		}
		case Constants.SUB_C_OUT_CART: // 用户出牌
		{
			// 变量定义
			CMD_C_OutCard pOutCard = new CMD_C_OutCard();

			pOutCard.bCardCount = Constants.atoi(vecArg[0]);
			pOutCard.setCardData(vecArg[1]);
			// int wHeadSize = sizeof(CMD_C_OutCard) -
			// sizeof(pOutCard.bCardData);
			// 用户效验
			tagUserData pUserData = pIServerUserItem.GetUserData();
			if (pUserData.cbUserStatus != Constants.US_PLAY)
				return true;

			// 消息处理
			return OnUserOutCard(pUserData.wChairID, pOutCard.bCardData, pOutCard.bCardCount);
		}
		case Constants.SUB_C_PASS_CARD: {
			// 用户效验
			tagUserData pUserData = pIServerUserItem.GetUserData();
			if (pUserData.cbUserStatus != Constants.US_PLAY)
				return true;

			// 消息处理
			return OnUserPassCard(pUserData.wChairID);
		}
		case Constants.SUB_C_TRUSTEE: // 玩家托管
		{
			// TODO
			CMD_C_UserTrustee pUserTrustee = new CMD_C_UserTrustee();

			pUserTrustee.wUserChairID = Constants.atoi(vecArg[0]);
			pUserTrustee.bTrustee = vecArg[1] == "true";
			m_bUserTrustee[pUserTrustee.wUserChairID] = pUserTrustee.bTrustee;
			String sData = pUserTrustee.getJsonData();
			SendTableData(Constants.INVALID_CHAIR, Constants.SUB_C_TRUSTEE, pUserTrustee, 0, sData);

			return true;
		}
		}

		return true;
	}

	boolean OnGameMessage(int wSubCmdID, Object pDataBuffer, int wDataSize, ServerUserItem pIServerUserItem) {
		// GAME_LOG( "<DDZTable>:\t %s\t\t chair:%d\n", GetMsgStr(wSubCmdID),
		// pIServerUserItem.GetUserData().wChairID );

		switch (wSubCmdID) {
		case Constants.SUB_C_USER_READY:// 用户准备
		{
			// 变量定义
			if (pIServerUserItem != null && !pIServerUserItem.IsAndroidUser()) {
				tagUserData pUserData = pIServerUserItem.GetUserData();
				return OnUserReady(pUserData.wChairID);
			}
			return true;
		}
		case Constants.SUB_C_LAND_SCORE: // 用户叫分
		{
			// 效验数据
			// ASSERT(wDataSize == sizeof(CMD_C_LandScore));
			// if (wDataSize != sizeof(CMD_C_LandScore)) return false;

			// 用户效验
			tagUserData pUserData = pIServerUserItem.GetUserData();
			if (pUserData.cbUserStatus != Constants.US_PLAY)
				return true;

			// 用户效验
			// ASSERT(m_wCurrentUser == pUserData.wChairID);
			if (m_wCurrentUser != pUserData.wChairID)
				return false;

			// 消息处理
			CMD_C_LandScore pLandScore = (CMD_C_LandScore) pDataBuffer;
			return OnUserLandScore(pUserData.wChairID, pLandScore.bLandScore);
		}
		case Constants.SUB_C_OUT_CART: // 用户出牌
		{
			// 变量定义
			CMD_C_OutCard pOutCard = (CMD_C_OutCard) pDataBuffer;
			// int wHeadSize = sizeof(CMD_C_OutCard) -
			// sizeof(pOutCard.bCardData);

			// 效验数据
			// ASSERT(wDataSize >= wHeadSize);
			// if (wDataSize < wHeadSize) return false;
			// ASSERT(wDataSize == (wHeadSize +
			// pOutCard.bCardCount*sizeof(pOutCard.bCardData[0])));
			// if (wDataSize != (wHeadSize +
			// pOutCard.bCardCount*sizeof(pOutCard.bCardData[0]))) return false;

			// 用户效验
			tagUserData pUserData = pIServerUserItem.GetUserData();
			if (pUserData.cbUserStatus != Constants.US_PLAY)
				return true;

			// 消息处理
			return OnUserOutCard(pUserData.wChairID, pOutCard.bCardData, pOutCard.bCardCount);
		}
		case Constants.SUB_C_PASS_CARD: {
			// 用户效验
			tagUserData pUserData = pIServerUserItem.GetUserData();
			if (pUserData.cbUserStatus != Constants.US_PLAY)
				return true;

			// 消息处理
			return OnUserPassCard(pUserData.wChairID);
		}
		case Constants.SUB_C_TRUSTEE: // 玩家托管
		{
			// 效验数据
			// ASSERT(wDataSize == sizeof(CMD_C_UserTrustee));
			// if (wDataSize != sizeof(CMD_C_UserTrustee)) return false;

			CMD_C_UserTrustee pUserTrustee = (CMD_C_UserTrustee) pDataBuffer;

			m_bUserTrustee[pUserTrustee.wUserChairID] = pUserTrustee.bTrustee;

			String sData = pUserTrustee.getJsonData();
			SendTableData(Constants.INVALID_CHAIR, Constants.SUB_C_TRUSTEE, pDataBuffer, wDataSize, sData);

			return true;
		}
		}

		return true;
	}

	boolean OnUserReady(int wChairID) {
		ServerUserItem pIServerUserItem = GetServerUserItem(wChairID);
		if (pIServerUserItem == null) {
			return false;
		}

		// 变量定义
		tagUserData pUserData = pIServerUserItem.GetUserData();
		boolean bLookonUser = (pUserData.cbUserStatus == Constants.US_LOOKON);

		// 状态效验
		// ASSERT(bLookonUser == false);
		// ASSERT(m_pIUserItem[pUserData.wChairID] == pIServerUserItem);
		if (bLookonUser == true)
			return false;
		if (pUserData.cbUserStatus >= Constants.US_PLAY)
			return true;

		// 设置变量
		pUserData.cbUserStatus = Constants.US_READY;

		SendUserStatus(pIServerUserItem);

		// 变量定义

		// 开始判断
		if (StartVerdict() == true) {
			TryStartGame();
			return true;
		}

		return true;
	}

	boolean OnUserLandScore(int wChairID, int bLandScore) {
		// 效验状态
		if (GetGameStatus() != Constants.GS_WK_SCORE)
			return true;
		if (wChairID != m_wCurrentUser)
			return false;

		// 效验参数
		if (((bLandScore > 3) && (bLandScore != 255)) || (bLandScore <= m_bLandScore)){
			//return false;
		}else{
			// 设置变量
			if (bLandScore != 255) {
				m_bLandScore = bLandScore;
				m_wBankerUser = m_wCurrentUser;
			}
		}
		m_bScoreInfo[wChairID] = bLandScore;

		// 开始判断
		if ((m_bLandScore == 3) || (m_wFirstUser == (wChairID + 1) % Constants.DDZ_PLAYER)) {
			// 重新发牌
			if (m_bLandScore == 0) {
				int cbSendGoodCard = Constants.rand() % Constants.GOOD_CARD_PERCENT;
				int cbAndroidUserCount = 0;
				int wAndroidUser[] = new int[Constants.DDZ_PLAYER];

				// 重置变量
				Constants.ZeroMemory(m_bScoreInfo);

				// 机器人个数
				for (int wChairID1 = 0; wChairID1 < Constants.DDZ_PLAYER; ++wChairID1) {
					ServerUserItem pServerUserItem = GetServerUserItem(wChairID1);
					if (pServerUserItem.IsAndroidUser()) {
						wAndroidUser[cbAndroidUserCount] = (wChairID1);
						++cbAndroidUserCount;
					}
				}

				int wHaveGoodCardAndroidUser = Constants.INVALID_CHAIR;
				if (cbAndroidUserCount > 0)
					wHaveGoodCardAndroidUser = wAndroidUser[Constants.rand() % cbAndroidUserCount];

				// 发送好牌
//				if (0 == cbSendGoodCard && wHaveGoodCardAndroidUser != Constants.INVALID_CHAIR) {
//					// 混乱扑克
//					int bRandCard[] = new int[54];
//					m_GameLogic.RandCardList(bRandCard, Constants.sizeof(bRandCard));
//
//					int cbGoodCard[] = new int[Constants.NORMAL_COUNT];
//					m_GameLogic.GetGoodCardData(cbGoodCard);
//
//					// 抽取好牌
//					m_GameLogic.RemoveGoodCardData(cbGoodCard, Constants.NORMAL_COUNT, bRandCard, Constants.FULL_COUNT);
//
//					// 分发扑克
//					Constants.CopyMemory(m_bHandCardData[wHaveGoodCardAndroidUser], cbGoodCard, Constants.NORMAL_COUNT);
//					m_bCardCount[wHaveGoodCardAndroidUser] = 17;
//					for (int i = 0, j = 0; i < Constants.DDZ_PLAYER; i++) {
//						if (i != wHaveGoodCardAndroidUser) {
//							m_bCardCount[i] = 17;
//							Constants.CopyMemory(m_bHandCardData[i], bRandCard[j * 17], 17);
//							++j;
//						}
//					}
//					Constants.CopyMemory(m_bBackCard, bRandCard[34], Constants.sizeof(m_bBackCard));
//					m_GameLogic.SortCardList(m_bBackCard, 3, Constants.ST_ORDER);
//				}else 
				{
					// 混乱扑克
					int bRandCard[] = new int[48];
					m_GameLogic.RandCardList(bRandCard, Constants.sizeof(bRandCard),this.m_paiMode);

					// 分发扑克
					for (int i = 0; i < Constants.DDZ_PLAYER; i++) {
						m_bCardCount[i] = 16;
						Constants.CopyMemory(m_bHandCardData[i], bRandCard,i * m_bCardCount[i],m_bCardCount[i]);
						//CopyMemory(&m_bHandCardData[i], &bRandCard[i*m_bCardCount[i]], sizeof(BYTE)*m_bCardCount[i]);
					}
					Constants.CopyMemory(m_bBackCard, bRandCard,48, Constants.sizeof(m_bBackCard));
					m_GameLogic.SortCardList(m_bBackCard, 0, Constants.ST_ORDER);
				}

				// 设置用户
				m_wCurrentUser = Constants.rand() % Constants.DDZ_PLAYER;
				m_wFirstUser = m_wCurrentUser;

				// 发送扑克
				CMD_S_SendAllCard SendAllCard = new CMD_S_SendAllCard();
				SendAllCard.wCurrentUser = m_wCurrentUser;

				// 手上扑克
				SendAllCard.bCardData = m_bHandCardData.clone();
				// 底牌扑克
				Constants.CopyMemory(SendAllCard.bBackCardData, m_bBackCard, 0);
				for (int i = 0; i < Constants.DDZ_PLAYER; i++) {
					String sData = SendAllCard.getJsonData();
					SendTableData(i, Constants.SUB_S_SEND_CARD, SendAllCard, 0, sData);
				}
				
	
				// 排列扑克
				for (int i = 0; i < Constants.DDZ_PLAYER; i++) {
					m_GameLogic.SortCardList(m_bHandCardData[i], m_bCardCount[i], Constants.ST_ORDER);
				}

				return true;
			}

			// 设置变量
			if (m_wBankerUser == Constants.INVALID_CHAIR)
				m_wBankerUser = m_wFirstUser;

			// 设置状态
			SetGameStatus(Constants.GS_WK_PLAYING);

			// 发送底牌
			m_bCardCount[m_wBankerUser] = 16;
			Constants.CopyMemory(m_bHandCardData[m_wBankerUser],16, m_bBackCard, Constants.sizeof(m_bBackCard));
			m_GameLogic.SortCardList(m_bHandCardData[m_wBankerUser], m_bCardCount[m_wBankerUser], Constants.ST_ORDER);

			// 出牌信息
			m_bTurnCardCount = 0;
			m_wTurnWiner = m_wBankerUser;
			m_wCurrentUser = m_wBankerUser;

			// 发送消息
			CMD_S_GameStart GameStart = new CMD_S_GameStart();
			GameStart.wLandUser = m_wBankerUser;
			GameStart.bLandScore = m_bLandScore;
			GameStart.wCurrentUser = m_wCurrentUser;
			Constants.CopyMemory(GameStart.bBackCard, m_bBackCard, Constants.sizeof(m_bBackCard));

			String sData = GameStart.getJsonData();
			SendTableData(Constants.INVALID_CHAIR, Constants.SUB_S_GAME_START, GameStart, 0, sData);
			

			return true;
		}

		// 设置用户
		m_wCurrentUser = (wChairID + 1) % Constants.DDZ_PLAYER;

		// 发送消息
		CMD_S_LandScore LandScore = new CMD_S_LandScore();
		LandScore.wLandUser = wChairID;
		LandScore.bLandScore = bLandScore;
		LandScore.wCurrentUser = m_wCurrentUser;
		LandScore.bCurrentScore = m_bLandScore;

		String sData = LandScore.getJsonData();
		SendTableData(Constants.INVALID_CHAIR, Constants.SUB_S_LAND_SCORE, LandScore, 0, sData);

		return true;
	}

	boolean OnUserOutCard(int wChairID, int bCardData[], int bCardCount) {
		System.out.println("跑得快，用户出牌,id:" + wChairID);
		// 效验状态
		if (GetGameStatus() != Constants.GS_WK_PLAYING)
			return true;
		if (wChairID != m_wCurrentUser)
			return false;
		
		//记录当前扑克
		currentCard.bCardCount = bCardCount;
		currentCard.setCardData(bCardData,bCardCount);
		
		// 排序扑克
		m_GameLogic.SortCardList(bCardData, bCardCount, Constants.ST_ORDER);

		// 类型判断
		int bCardType = m_GameLogic.GetCardType(bCardData, bCardCount);
		if (bCardType == Constants.CT_ERROR)
			return false;

		// 更随出牌
		if (m_bTurnCardCount == 0)
			m_bTurnCardCount = bCardCount;
		else if (m_GameLogic.CompareCard(m_bTurnCardData, bCardData, m_bTurnCardCount, bCardCount) == false)
			return false;

		// 删除扑克
		if (m_GameLogic.RemoveCard(bCardData, bCardCount, m_bHandCardData[wChairID], m_bCardCount[wChairID]) == false)
			return false;
		m_bCardCount[wChairID] -= bCardCount;

		// 出牌记录
		m_bTurnCardCount = bCardCount;
		m_bOutCardCount[wChairID]++;
		Constants.CopyMemory(m_bTurnCardData, bCardData);

		// 炸弹判断
		// 炸弹判断
		if ((bCardType == Constants.CT_BOMB_CARD) || (bCardType == Constants.CT_MISSILE_CARD)){
			m_wBombTime *= 2;
			m_boomCountArray[wChairID]++;
			m_vecBombCount[wChairID]++;
			if(m_bCardCount[wChairID] == 0){
				//炸弹是最后的
				if(wChairID == 0){
					m_bombArray[0] += 10;
					m_bombArray[1] -= 5;
					m_bombArray[2] -= 5;
				}
                if(wChairID == 1){
                	m_bombArray[1] += 10;
					m_bombArray[0] -= 5;
					m_bombArray[2] -= 5;
				}
                if(wChairID == 2){
                	m_bombArray[2] += 10;
					m_bombArray[1] -= 5;
					m_bombArray[0] -= 5;
				}
			}
		}		

		// 切换用户
		m_wTurnWiner = wChairID;
		if (m_bCardCount[wChairID] != 0) {
			if (bCardType != Constants.CT_MISSILE_CARD)
				m_wCurrentUser = (m_wCurrentUser + 1) % Constants.DDZ_PLAYER;
		} else
			m_wCurrentUser = Constants.INVALID_CHAIR;

		// 构造数据
		CMD_S_OutCard OutCard = new CMD_S_OutCard();
		OutCard.bCardCount = bCardCount;
		OutCard.wOutCardUser = wChairID;
		OutCard.wCurrentUser = m_wCurrentUser;
		Constants.CopyMemory(OutCard.bCardData, m_bTurnCardData);

		// 发送数据

		String sData = OutCard.getJsonData();
		SendTableData(Constants.INVALID_CHAIR, Constants.SUB_S_OUT_CARD, OutCard, 0, sData);

		// 出牌最大
		if (bCardType == Constants.CT_MISSILE_CARD)
			m_bTurnCardCount = 0;

		// 结束判断
		if (m_wCurrentUser == Constants.INVALID_CHAIR)
			OnEventGameEnd(wChairID, null, Constants.GER_NORMAL);

		return true;
		
	}
	boolean OnUserPassCard(int wChairID) {
		// 效验状态
		if (GetGameStatus() != Constants.GS_WK_PLAYING)
			return true;
		if ((wChairID != m_wCurrentUser) || (m_bTurnCardCount == 0))
			return false;

		// 设置变量
		m_wCurrentUser = (m_wCurrentUser + 1) % Constants.DDZ_PLAYER;
		if (m_wCurrentUser == m_wTurnWiner){
			m_bTurnCardCount = 0;
			// 排序扑克
			m_GameLogic.SortCardList(currentCard.bCardData, currentCard.bCardCount, Constants.ST_ORDER);

			// 类型判断
			int bCardType = m_GameLogic.GetCardType(currentCard.bCardData, currentCard.bCardCount);
			// 炸弹判断
			if ((bCardType == Constants.CT_BOMB_CARD) || (bCardType == Constants.CT_MISSILE_CARD)){
				if(m_wCurrentUser == 0){
					m_bombArray[0] += 10;
					m_bombArray[1] -= 5;
					m_bombArray[2] -= 5;
				}
                if(m_wCurrentUser == 1){
                	m_bombArray[1] += 10;
					m_bombArray[0] -= 5;
					m_bombArray[2] -= 5;
				}
                if(m_wCurrentUser == 2){
                	m_bombArray[2] += 10;
					m_bombArray[1] -= 5;
					m_bombArray[0] -= 5;
				}
					
			}
		}
			

		// 发送数据
		CMD_S_PassCard PassCard = new CMD_S_PassCard();
		PassCard.wPassUser = wChairID;
		PassCard.wCurrentUser = m_wCurrentUser;
		PassCard.bNewTurn = (m_bTurnCardCount == 0) ? 1 : 0;

		String sData = PassCard.getJsonData();
		SendTableData(Constants.INVALID_CHAIR, Constants.SUB_S_PASS_CARD, PassCard, 0, sData);

		return true;
	}

	boolean IsGameStarted() {
		return m_bGameStarted;
	}

	// 锁定状态
	boolean IsTableLocked() {
		return (StringUtils.isNotEmpty(m_szPassword));
	}

	String m_szPassword;

	// 发送状态
	boolean SendTableStatus() {
		// 效验参数

		CMD_GR_TableStatus TableStatus = new CMD_GR_TableStatus();
		TableStatus.wTableID = mTableID;
		TableStatus.bPlayStatus = IsGameStarted() ? 1 : 0;

		String sData = TableStatus.getJsonData();
		// 发送数据
		SendTableData(Constants.INVALID_CHAIR, Constants.SUB_GR_TABLE_STATUS, TableStatus, 0, sData);

		return true;
	}

	

	// 发送用户分数
	boolean SendUserScore(ServerUserItem pServerUserItem) {
		// 效验参数
		// ASSERT(pServerUserItem != null);
		// ASSERT(pServerUserItem.IsActive() == true);
		if (pServerUserItem.IsActive() == false)
			return false;

		tagUserData pUserData = pServerUserItem.GetUserData();

		// 发送数据
		CMD_GR_UserScore UserScore = new CMD_GR_UserScore();
		UserScore.dwUserID = pUserData.dwUserID;
		UserScore.lScore = pUserData.lScore + pUserData.lStorageScore; // 用户分数
		UserScore.lGameGold = pUserData.lGameGold; // 游戏金币//
		UserScore.lStorageGold = pUserData.lStorageGold; // 存储金币
		UserScore.lWinCount = pUserData.lWinCount; // 胜利盘数
		UserScore.lLostCount = pUserData.lLostCount; // 失败盘数
		UserScore.lDrawCount = pUserData.lDrawCount; // 和局盘数
		UserScore.lFleeCount = pUserData.lFleeCount; // 断线数目
		UserScore.lExperience = pUserData.lExperience; // 用户经验
		String sData = UserScore.getJsonData();
		SendTableData(Constants.INVALID_CHAIR, Constants.SUB_GR_USER_SCORE, UserScore, 0, sData);
		return true;
	}

	// 发送状态
	boolean SendUserStatus(ServerUserItem pServerUserItem) {
		// 效验参数
		// ASSERT(pServerUserItem != null);
		// ASSERT(pServerUserItem.IsActive() == true);
		if (pServerUserItem.IsActive() == false)
			return false;

		// 变量定义
		CMD_GR_UserStatus UserStatus = new CMD_GR_UserStatus();
		tagUserData pUserData = pServerUserItem.GetUserData();

		// 构造数据
		UserStatus.dwUserID = pServerUserItem.dwUserID;
		UserStatus.wTableID = pUserData.wTableID;
		UserStatus.wChairID = pServerUserItem.wChairID;
		UserStatus.cbUserStatus = pServerUserItem.cbUserStatus;

		String sData = UserStatus.getJsonData();
		// 发送数据
		SendTableData(Constants.INVALID_CHAIR, Constants.SUB_GR_USER_STATUS, UserStatus, 0, sData);
		return true;
	}

	boolean ConcludeGame() {
		// 设置状态
		m_bGameStarted = false;
		m_dwTimeStart = 0;
		m_bGameStatus = Constants.GS_WK_FREE;

		RepositTableFrameSink();

		for (int i = 0; i < Constants.DDZ_PLAYER; ++i) {
			if (m_pIUserItem[i] != null) {
				m_pIUserItem[i].SetUserStatus(Constants.US_SIT, GetTableID(), i);
				m_pIUserItem[i].cbUserStatus = Constants.US_NULL;
			}
			if (mPlayers[i] != null) {
				mPlayers[i].OnGameEnd();
			}
		}

		return true;
	}
	boolean StartGame(int _Uid){
		int wChairID = FindSeat(_Uid);
		if (wChairID < 3) {
			m_pIUserItem[wChairID].cbUserStatus = Constants.US_READY;
			SendUserStatus(m_pIUserItem[wChairID]);
		}
		TryStartGame();
		return false;
	}
	boolean TryStartGame(){
		int cntReady = 0;
		for (int i = 0; i < m_pIUserItem.length; i++) {
			ServerUserItem user = m_pIUserItem[i];
			if (user != null && user.cbUserStatus == Constants.US_READY) {
				cntReady++;
			}
		}
		if (cntReady == 3) {
			StartGame();
		}
		return false;
	}
	int AddRobot() {
		//没用
		for (int i = 0; i < Constants.DDZ_PLAYER; ++i) {
			if (m_pIUserItem[i] == null ||  m_pIUserItem[i].getUid() == 0) {
				//m_pIUserItem[i] = new ServerUserItem();
				tagUserData pUserData = m_pIUserItem[i].GetUserData();
				AIPlayer user1 = new AIPlayer();
				mPlayers[i] = user1;
				m_pIUserItem[i].SetAndroidUser(true);

				pUserData.dwUserID = g_AndroidUIDIndex++;
				m_pIUserItem[i].setUid(pUserData.dwUserID);
				pUserData.lScore = 1000000000;
				pUserData.szName = Constants.getRandName(Constants.random(10000, 90000));
				if (Constants.random(0, 100) % 2 == 1) {
					// string random_name =
					// g_vecNames[dt::Math:getRandNrandomame(0,g_vecNames.size()-1)];
					// sprintf(pUserData.szName,random_name);
				}
				mPlayers[i].SetTable(this);
				mPlayers[i].SetChairID(i);
				m_pIUserItem[i].SetUserStatus(Constants.US_SIT, GetTableID(), i);

				return 1;
			}
		}
		
		return 0;
	}
	public void DoAddGoldRobotPlayer(){
		int userCnt = 0;
		for(int i = 0;i < 3;i++){
			if(m_pIUserItem[i].dwUserID > 0){
				userCnt++;
			}
		}
		if(userCnt == 3){
			setNeedRobot(false,0);
			return;
		}
		
		int robot_gold = (int) RobotMgr.getInstance().getRandRobotGold(m_ruchang,m_difen);
		int gold = GoldMgr.getInstance().applyRobotGold(robot_gold);
		if(gold == 0){
			//申请不到足够的金币
			setNeedRobot(false,0);
			return;
		}
		Robot robot = RobotMgr.getInstance().AllocRobot();
		int robot_uid = robot.uid;
		SHMUser user = dthall.getInstance().getUserInfo(robot_uid);
		if(user == null){
			setNeedRobot(false,0);
			return;
		}
		user.m_lTotalCoin = gold;
		user.setApplyNum(gold);

		ArrayList<Integer> vecEmpty = new ArrayList<>();
		for (int i = 0; i < 3; i++) {
			if (m_pIUserItem[i].dwUserID == 0) {
				vecEmpty.add(i);
			}
		}
		if (vecEmpty.size() > 0) {
			if(this.m_clubId != 0){
				GameAgent agent = new GameAgent(user);
				net.sf.json.JSONObject json = new net.sf.json.JSONObject();
				String data = "JoinRoom|" + this.m_clubId + "|" + this.m_dwTableID;
				json.put("data", data);
				ClubMgr.getInstance().m_clubHandler.HandleOn_ClubInfo(agent, json);
			}else{
				OnUserSit(robot_uid);
			}

			// 主动准备
			class GoldReadyTask extends TimerTask{
				@Override
				public void run() {
					Server.Poker.PDK.PDKTableMgr.getInstance().Handle_onStart(robot_uid, new String[2]);					
				}				
			}
			Timer timer = new Timer();
			timer.schedule(new GoldReadyTask(),1000 * CommonDef.randInt(1, 4));
		}
	}
	public void DoAddRmbRobotPlayer(){
		int userCnt = 0;
		for(int i = 0;i < 3;i++){
			if(m_pIUserItem[i].dwUserID > 0){
				userCnt++;
			}
		}
		if(userCnt == 3){
			setNeedRobot(false,0);
			return;
		}
		
		double robot_rmb = RobotMgr.getInstance().getRandRobotGold(m_ruchang,m_doubleDiFen);
		robot_rmb += Math.random() * 2;
		BigDecimal b = new BigDecimal(robot_rmb);
		robot_rmb = b.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue(); 
		double rmb = GoldMgr.getInstance().applyRobotRmb(robot_rmb);
		if(rmb == 0){
			//申请不到足够rmb
			setNeedRobot(false,0);
			return;
		}
		Robot robot = RobotMgr.getInstance().AllocRobot();
		int robot_uid = robot.uid;
		SHMUser user = dthall.getInstance().getUserInfo(robot_uid);
		if(user == null){
			setNeedRobot(false,0);
			return;
		}
		user.setRMb1v1Value(rmb);
		user.setApplyNum(rmb);

		ArrayList<Integer> vecEmpty = new ArrayList<>();
		for (int i = 0; i < 3; i++) {
			if (m_pIUserItem[i].dwUserID == 0) {
				vecEmpty.add(i);
			}
		}
		if (vecEmpty.size() > 0) {
			if(this.m_clubId != 0){
				GameAgent agent = new GameAgent(user);
				net.sf.json.JSONObject json = new net.sf.json.JSONObject();
				String data = "JoinRoom|" + this.m_clubId + "|" + this.m_dwTableID;
				json.put("data", data);
				ClubMgr.getInstance().m_clubHandler.HandleOn_ClubInfo(agent, json);
			}else{
				OnUserSit(robot_uid);
			}

			// 主动准备
			class GoldReadyTask extends TimerTask{
				@Override
				public void run() {
					Server.Poker.PDK.PDKTableMgr.getInstance().Handle_onStart(robot_uid, new String[2]);			
				}				
			}
			Timer timer = new Timer();
			timer.schedule(new GoldReadyTask(),1000 * CommonDef.randInt(1, 4));
		}
	}
	public void DoAddRobotPlayer(){
		if(m_roomType.equals("GOLD")){
			DoAddGoldRobotPlayer();
		}else if(m_roomType.equals("DWC")){
			DoAddRmbRobotPlayer();
		}
	}
	boolean StartGame() {
		// 效验状态
		if (m_bGameStarted == true)
			return false;
		m_curStage = "STAGE_START";
		m_aiDelayTime = 100000;
		m_bGameStarted = true;
		m_bTableStarted = true;
		m_dwTimeStart = (int) Constants.time(null);
		for(int i=0;i<3;i++){
			m_bombArray[i] = 0;
			m_boomCountArray[i] = 0;
		}

		SHMUser user = null;
		for (int i = 0; i < Constants.DDZ_PLAYER; ++i) {
			
			if (m_pIUserItem[i] != null && mPlayers[i] != null) {
				if (!m_pIUserItem[i].IsAndroidUser()
						&& (user = getAppHandler().getUserInfo(m_pIUserItem[i].getUid())) != null) {
				}
				m_pIUserItem[i].SetUserStatus(Constants.US_PLAY, GetTableID(), i);
				mPlayers[i].OnGameBegin();
			}
		}
		return OnEventGameStart();
	}

	ServerUserItem GetServerUserItem(int wChairID) {
		if (wChairID >= Constants.DDZ_PLAYER) {
			return null;
		}
		// ASSERT(wChairID < DDZ_PLAYER);
		if (wChairID >= Constants.DDZ_PLAYER)
			return null;
		return m_pIUserItem[wChairID];
	}

	boolean SendTableData(int wChairID, int wSubCmdID, Object pData, int wDataSize, String data) {
		// 群发用户
		if (wChairID == Constants.INVALID_CHAIR) {
			for (int i = 0; i < Constants.DDZ_PLAYER; i++) {
				if (mPlayers[i] != null) {
					mPlayers[i].SendGameMessage(wSubCmdID, pData, wDataSize, data);
				}
			}

			return true;
		}

		// 单一发送
		if (wChairID < Constants.DDZ_PLAYER) {
			if (mPlayers[wChairID] != null) {
				mPlayers[wChairID].SendGameMessage(wSubCmdID, pData, wDataSize, data);
			}
			return true;
		}

		return false;
	}

	int GetGameStatus() {
		return m_bGameStatus;
	}

	void SetGameStatus(int cbGameStatus) {
		m_bGameStatus = cbGameStatus;
	}

	int m_cbGameStatus;
	public int m_Creator;
	public String m_payWay;
	public int m_byCostGem;
	public int m_dwTableID;

	boolean SendTableInfo(int wChairID) {
		CMD_GR_TableInfo TableInfo = new CMD_GR_TableInfo();
		TableInfo.wTableID = GetTableID();

		for (int i = 0; i < Constants.DDZ_PLAYER; i++) {
			ServerUserItem pIUserItem = GetServerUserItem(i);

			if (pIUserItem != null) {
				tagUserData pUserData = pIUserItem.GetUserData();
				// 用户属性
				TableInfo.UserData[i] = pUserData; // 头像索引
			}
		}
		TableInfo.bStatus = GetGameStatus();

		String sData = TableInfo.getJsonData();
		SendTableData(Constants.INVALID_CHAIR, Constants.SUB_GR_TABLE_INFO, TableInfo, 0, sData);
		return false;
	}

	void RepositTableFrameSink() {
		// 游戏变量
		m_wBombTime = 1;
		m_bLandScore = 0;
		m_bMingCard = 0;
		m_bHaveSendCard = 0;
		m_bCurrentState = 0;
		m_wOutBombCount = 0;
		m_wBankerUser = Constants.INVALID_CHAIR;
		m_wCurrentUser = Constants.INVALID_CHAIR;
		Constants.memset(m_bScoreTimes, 0);
		Constants.memset(m_bCallScoreTimes, 0);
		Constants.memset(m_bCallScoreTag, 0);
		Constants.memset(m_bCallBanker, 0);
		Constants.memset(m_bScoreInfo, 0);

		// 运行信息
		m_bTurnCardCount = 0;
		m_wTurnWiner = Constants.INVALID_CHAIR;
		Constants.memset(m_bTurnCardData, 0);
		Constants.memset(m_bUserTrustee, false);

		// 扑克信息
		Constants.memset(m_bBackCard, 0);
		Constants.memset(m_bCardCount, 0);
		Constants.memset(m_bOutCardCount, 0);
		Constants.memset(m_bHandCardData, 0);

		m_bGameStarted = false;
	}

	boolean StartVerdict() {
		// 比赛判断
		if (m_bGameStarted == true)
			return false;

		// 准备人数
		int wReadyUserCount = 0;
		tagUserData pUserData = null;
		for (int i = 0; i < Constants.DDZ_PLAYER; i++) {
			if (m_pIUserItem[i] != null && m_pIUserItem[i].getUid() != 0) {
				wReadyUserCount++;
				pUserData = m_pIUserItem[i].GetUserData();
				if (pUserData.cbUserStatus != Constants.US_READY)
					return false;
			}
		}

		// 条件判断
		if (wReadyUserCount > 1L) {
			return (wReadyUserCount == Constants.DDZ_PLAYER);
		}

		return false;
	}

	boolean SendGameScene(int _Uid, int cbGameStatus) {
		
			SUBCMD_S_Table cmd = new SUBCMD_S_Table();
			cmd.m_dwTableID = m_dwTableID;// 房间ID
			cmd.m_bTableStarted = m_bTableStarted ? 1 : 0;// 房间ID
			cmd.m_bGameStarted = m_bGameStarted ? 1 : 0;// 是否开始
			cmd.m_byRound = m_byRound;
			cmd.m_byMaxRound = m_byMaxRound;
			cmd.m_cntLookon = 1;// 观众
			cmd.m_param = this.m_roomParam;

			for (int i = 0; i < 3; i++) {
				cmd.m_seatInfo[i].m_lUid = m_pIUserItem[i].dwUserID;// UID
				cmd.m_seatInfo[i].m_iSeatId = i;// 座位号ID
				cmd.m_seatInfo[i].m_iTotalCoin = m_pIUserItem[i].lUserScore;

				cmd.m_seatInfo[i].m_NickName = m_pIUserItem[i].szNickName;// NICKNAME
				cmd.m_seatInfo[i].m_iBetCoin = 0;//
				cmd.m_seatInfo[i].m_cbGender = m_pIUserItem[i].cbGender;
				cmd.m_seatInfo[i].m_iAvatar = m_pIUserItem[i].dwFaceID;//
				cmd.m_seatInfo[i].m_cbUserStatus = m_pIUserItem[i].cbUserStatus;// 用户状态
				cmd.m_seatInfo[i].m_iVipLevel = m_pIUserItem[i].cbVipLevel;// VIP
																			// LEVEL
				cmd.m_seatInfo[i].m_iTitle = 0;// 称号
				cmd.m_seatInfo[i].m_isLookon = 0;// 是否观众
				cmd.m_seatInfo[i].szIP = m_pIUserItem[i].szIP;
				if(this.isGoldType()){
					cmd.m_seatInfo[i].m_iTotalCoin = m_pIUserItem[i].lUserCoin;
				}else if(this.isDwcType()){
					cmd.m_seatInfo[i].m_iTotalCoin = m_pIUserItem[i].lUserRmb;
				}
			}

			SendData(_Uid, cmd.getJsonData());
			for (int i = 0; i < 3; i++) {
				if (m_pIUserItem[i].dwUserID > 0) {
					SendAvatar(m_pIUserItem[i].dwUserID);
				}
			}
		

		int wChiarID = FindSeat(_Uid);
		String temp = "";
		String msgBuf = "";
		switch (cbGameStatus) {
		case Constants.GS_WK_FREE: // 空闲状态
		{
			// 构造数据
			CMD_S_StatusFree StatusFree = new CMD_S_StatusFree();

			// 设置变量
			StatusFree.lBaseScore = m_lCellScore;
			StatusFree.tableStart = m_bTableStarted == true?1:0;

			temp = String.format("\"cbGameStatus\":%d,\"lBaseScore\":%d,\"wChiarID\":%d,\"m_bTableStarted\":%d", cbGameStatus, StatusFree.lBaseScore,wChiarID,StatusFree.tableStart);
			// 发送场景
			return SendTableData(wChiarID, Constants.SUB_S_GAME_SCENE, msgBuf, 0, temp);			
		}
		case Constants.GS_WK_SCORE: // 叫分状态
		{
			// 构造数据
			CMD_S_StatusScore StatusScore = new CMD_S_StatusScore();

			// 设置变量
			StatusScore.bLandScore = m_bLandScore;
			StatusScore.wCurrentUser = m_wCurrentUser;
			StatusScore.lBaseScore = m_lCellScore;
			StatusScore.bScoreInfo = m_bScoreInfo.clone();
			// CopyMemory(StatusScore.bCardData,m_bHandCardData[wChiarID],m_bCardCount[wChiarID]);
			StatusScore.bCardData = m_bHandCardData.clone();
			StatusScore.bUserTrustee = m_bUserTrustee.clone();

			String sData = StatusScore.getJsonData();
			temp = String.format("\"cbGameStatus\":%d ,%s", cbGameStatus, sData);
			// 发送场景
			return SendTableData(wChiarID, Constants.SUB_S_GAME_SCENE, msgBuf, 0, temp);
		}
		case Constants.GS_WK_PLAYING: // 游戏状态
		{
			// 构造数据
			CMD_S_StatusPlay StatusPlay = new CMD_S_StatusPlay();

			// 设置变量
			StatusPlay.wBombTime = m_wBombTime;
			StatusPlay.wLandUser = m_wBankerUser;
			StatusPlay.wCurrentUser = m_wCurrentUser;
			StatusPlay.wLastOutUser = m_wTurnWiner;
			StatusPlay.bLandScore = m_bLandScore;
			StatusPlay.bTurnCardCount = m_bTurnCardCount;
			StatusPlay.lBaseScore = m_lCellScore;
			Constants.CopyMemory(StatusPlay.bBackCard, m_bBackCard);
			Constants.CopyMemory(StatusPlay.bCardCount, m_bCardCount);
			Constants.CopyMemory(StatusPlay.bTurnCardData, m_bTurnCardData);
			//CopyMemory(StatusPlay.bCardData,m_bHandCardData[wChiarID],m_bCardCount[wChiarID]);
			StatusPlay.bCardData = m_bHandCardData.clone();
			Constants.CopyMemory(StatusPlay.bUserTrustee, m_bUserTrustee);

			String sData = StatusPlay.getJsonData();
			temp = String.format("\"cbGameStatus\":%d ,%s", cbGameStatus, sData);

			// 发送场景
			return SendTableData(wChiarID, Constants.SUB_S_GAME_SCENE, msgBuf, 0, temp);
		}
		}

		return false;		
	}
	

	boolean send(int lUid, int wMsgType, MSG_PACKET pMsg, int wSize) {
		MSG_FOR_TABLE pTable = (MSG_FOR_TABLE) pMsg;
		pMsg.SetMsgType(wMsgType);
		// getAppHandler().send(lUid, pMsg, wSize);
		onSend(lUid, pTable.getJsonData());
		return true;
	}

	boolean onSend(int lUid, String data) {
		((PDKTableMgr) getAppHandler()).onSend(lUid, data);
		return true;
	}

	private PDKTableMgr getAppHandler() {
		return m_objAppHandler;
	}

	@Override
	public int GetID() {
		return mTableID;
	}

	@Override
	public String GetType() {
		return "PDK";
	}

	@Override
	public int GetCreator() {
		return m_Creator;
	}

	@Override
	public void OnClientClose(int lUid) {
		OnUserStandUp(lUid,false);
	}


	public int CanSit(int _Uid) {
		if(this.isDwcType()){
			UserRedisInfo info = dthall.getInstance().getSafeUserRedisInfo(_Uid);
			if(info.json.optInt("userRmbType") == 1 && !canUserJoinRentRoom(info.json.optInt("upAgentUid"))){
				return 22;
			}else if(info.json.optInt("userRmbType") == 0 && m_clubOwnerId != 0){
				UserRedisInfo clubInfo = dthall.getInstance().getSafeUserRedisInfo(m_clubOwnerId);
				if(clubInfo.json.optInt("userRmbType") == 1){
					return 23;
				}
			}
		}
		if (m_Creator == _Uid) {
			return 14;
		}

		for (int i = 0; i < 3; i++) {
			if (m_pIUserItem[i].dwUserID == _Uid) {
				return i;
			}
		}
		SHMUser user = dthall.getInstance().getUserInfo(_Uid);
		if (user != null && isZuJuType()) {
			if (m_payWay.equalsIgnoreCase("CLUBPAY") || m_payWay.equalsIgnoreCase("WINPAY")) {
				if(m_payWay.equalsIgnoreCase("CLUBPAY")){
					for (int i = 0; i < 4; i++) {
						if (m_pIUserItem[i].dwUserID == 0) {
							return i;
						}
					}
					return 12;
				}
				if (user.getGem(0) < m_byCostGem * 3) {
					return 11;
				}
			}else{
				if (m_payWay.equalsIgnoreCase("AAPAY") )
				{
					if (user.getGem(0) < m_byCostGem) {
						return 11;
					}
				}
			}
		}

		if(user != null && isGoldType()){
			if(user.getCoin(0) < m_ruchang){
				return 21;
			}
		}
		if(user != null && isDwcType()){
			if(user.getRmb1v1Value() < m_ruchang){
				return 21;
			}
		}
		for (int i = 0; i < 3; i++) {
			if (m_pIUserItem[i].dwUserID == 0) {
				return i;
			}
		}
		return 12;
	}

	@Override
	public int FindSeat(int _Uid) {
		for (int bySeatID = 0; bySeatID < 3; bySeatID++) {
			if (m_pIUserItem[bySeatID].dwUserID == _Uid) {
				return bySeatID;
			}
		}
		return Constants.INVALID_CHAIR;
	}
	public void SendLocationData(SHMUser user) {
		JSONObject data = new JSONObject();
		data.put("loc", user.getGpsLocInfo());
		data.put("uid", user.getUid());
		data.put("command", "GPS_LOC");
		SendData(Constants.INVALID_CHAIR, data.toString());

		for (short i = 0; i < m_pIUserItem.length; i++) {
			if (m_pIUserItem[i].dwUserID > 0) {
				if (m_pIUserItem[i].isAndroidUser == 0) {
					int uid = m_pIUserItem[i].dwUserID;
					SHMUser other = dthall.getInstance().getUserInfo(uid);
					if(other != null){
						data.put("uid", other.getUid());
						data.put("loc", other.getGpsLocInfo());
						dthall.getInstance().onSend(user.getUid(), data.toString());
					}
				}
			}
		}
	}

	public void SendGpsData(SHMUser user) {
		JSONObject data = new JSONObject();
		List<Double> gpsData = user.getLocateInfo();
		data.put("lng", gpsData.get(0));
		data.put("lat", gpsData.get(1));
		data.put("command", "GPS_DATA");
		data.put("uid", user.getUid());
		SendData(Constants.INVALID_CHAIR, data.toString());

		for (short i = 0; i < m_pIUserItem.length; i++) {
			if (m_pIUserItem[i].dwUserID > 0) {
				if (m_pIUserItem[i].isAndroidUser == 0) {
					int uid = m_pIUserItem[i].dwUserID;
					SHMUser other = dthall.getInstance().getUserInfo(uid);
					if (other != null) {
						gpsData = other.getLocateInfo();
						data.put("uid", other.getUid());
						data.put("lng", gpsData.get(0));
						data.put("lat", gpsData.get(1));
						dthall.getInstance().onSend(user.getUid(), data.toString());
					}
				}
			}
		}
	}
	@Override
	public void OnUserSit(int _Uid) {
		
		SHMUser user = dthall.getInstance().getUserInfo(_Uid);

		if (user != null) {
			SendGpsData(user);
			SendLocationData(user);
		}
		//因为斗地主原来的代码用到了  mPlayers，所以要加以下代码》。。。。。。。。。
		onLogin(_Uid);
		OnUserSit(user);
		
		
		int bySeatID = FindSeat(_Uid);
		if (bySeatID < 3) {
			m_pIUserItem[bySeatID].cbOnline = Constants.US_NULL;
			
		}
		
		if (user != null) {
			for (int i = 0; i < 3; i++) {
				if (m_pIUserItem[i].dwUserID == _Uid) {
					m_pIUserItem[i].dwUserID = _Uid;
					m_pIUserItem[i].wChairID = i;
					m_pIUserItem[i].dwFaceID = 0;
					m_pIUserItem[i].cbGender = user.getSex();
					m_pIUserItem[i].szNickName = user.getNickName(null);
					m_pIUserItem[i].szIP = user.getIP(null);
					m_pIUserItem[i].lUserCoin = user.getCoin(0);
					if(this.isDwcType()){
						m_pIUserItem[i].lUserRmb = user.getRmb1v1Value();
					}

					if(user.isAndroidPlayer()){
						m_pIUserItem[i].isAndroidUser = 2;
						AIPlayer user1 = new AIPlayer();
						mPlayers[i] = user1;
						mPlayers[i].SetTable(this);
						mPlayers[i].SetChairID(i);
						m_pIUserItem[i].SetAndroidUser(true);
					}
					SUBCMD_S_Sit cmd = new SUBCMD_S_Sit();
					cmd.m_lUid = _Uid;
					cmd.m_wUserChairID = m_pIUserItem[i].wChairID;
					cmd.m_dwTableID = m_dwTableID;
					cmd.m_lUserScore = m_pIUserItem[i].lUserScore;
					cmd.m_cbGender = m_pIUserItem[i].cbGender;
					cmd.m_iAvatar = m_pIUserItem[i].dwFaceID;
					cmd.szNickName = user.getNickName(null);
					cmd.szIP = user.getIP(null);
					cmd.m_param = this.m_roomParam;
					if(this.isDwcType() && this.m_dwcKouYing != 0){
						cmd.dwcKouYingRate = m_dwcKouYingRate;
					}

					if(this.inHall()){
						cmd.m_kouYingJuShu = 0;
					}else{
						cmd.m_kouYingJuShu = GoldMgr.getInstance().getKouWinJuShuInClub();
					}
					if(this.isGoldType()){
						cmd.m_lUserCoin = user.getCoin(0);
					}else if(this.isDwcType()){
						cmd.m_lUserCoin = user.getRmb1v1Value();
					}

					SendData(Constants.INVALID_CHAIR, cmd.getJsonData());

					SendGameScene(_Uid, m_bGameStatus);
					SendAvatar(m_pIUserItem[i].dwUserID);

					return;
				}
			}
			for (int i = 0; i < 3; i++) {
				if (m_pIUserItem[i].dwUserID == 0) {
					m_pIUserItem[i].dwUserID = _Uid;
					m_pIUserItem[i].lUserScore = 0;
					m_pIUserItem[i].wChairID = i;
					m_pIUserItem[i].dwFaceID = 0;
					m_pIUserItem[i].cbGender = user.getSex();
					m_pIUserItem[i].szNickName = user.getNickName(null);
					m_pIUserItem[i].szIP = user.getIP(null);
					m_pIUserItem[i].lUserCoin = user.getCoin(0);
					if(this.isDwcType()){
						m_pIUserItem[i].lUserRmb = user.getRmb1v1Value();
					}

					if(user.isAndroidPlayer()){
						m_pIUserItem[i].isAndroidUser = 2;
						AIPlayer user1 = new AIPlayer();
						mPlayers[i] = user1;
						mPlayers[i].SetTable(this);
						mPlayers[i].SetChairID(i);
						m_pIUserItem[i].SetAndroidUser(true);
					}
					SUBCMD_S_Sit cmd = new SUBCMD_S_Sit();
					cmd.m_lUid = _Uid;
					cmd.m_wUserChairID = m_pIUserItem[i].wChairID;
					cmd.m_dwTableID = m_dwTableID;
					cmd.m_lUserScore = m_pIUserItem[i].lUserScore;
					cmd.m_cbGender = m_pIUserItem[i].cbGender;
					cmd.m_iAvatar = m_pIUserItem[i].dwFaceID;
					cmd.szNickName = user.getNickName(null);
					cmd.szIP = user.getIP(null);
					cmd.m_param = this.m_roomParam;
					if(this.isDwcType() && this.m_dwcKouYing != 0){
						cmd.dwcKouYingRate = m_dwcKouYingRate;
					}
					if(this.isGoldType()){
						cmd.m_lUserCoin = user.getCoin(0);
					}else if(this.isDwcType()){
						cmd.m_lUserCoin = user.getRmb1v1Value();
					}

					if(this.inHall()){
						cmd.m_kouYingJuShu = 0;
					}else{
						cmd.m_kouYingJuShu = GoldMgr.getInstance().getKouWinJuShuInClub();
					}
					SendData(Constants.INVALID_CHAIR, cmd.getJsonData());

					SendGameScene(_Uid, m_bGameStatus);
					return ;

				}
			}
		}
		

		return;
		
		
	}
	void OnUserSit(SHMUser user){
		if (user == null || user.getUid() == 0) {
			return;
		}

		int wChairID = Constants.INVALID_CHAIR;
		
		if (wChairID == Constants.INVALID_CHAIR) {
			for (int i = 0; i < Constants.DDZ_PLAYER; i++) {
				if (m_pIUserItem[i] != null && m_pIUserItem[i].getUid() == user.getUid()) {
					wChairID = i;
					break;
				}
			}
		}
		if (wChairID == Constants.INVALID_CHAIR) {
			for (int i = 0; i < Constants.DDZ_PLAYER; i++) {
				if (m_pIUserItem[i] == null || m_pIUserItem[i].getUid() == 0) {
					wChairID = i;
					break;
				}
			}
		}

		if (wChairID != Constants.INVALID_CHAIR) {
			
			//自动换下一家叫地主
			tagUserData pUserData = m_pIUserItem[wChairID].GetUserData();
			pUserData.dwUserID = user.getUid();
			pUserData.lScore = user.getCoin(0);
			pUserData.dwFaceID = user.getAvatar();
			pUserData.cbGender = user.getSex();
			pUserData.cbMemberOrder = user.getVip();
			pUserData.szName = user.getNickName(null);
			// 发消息用户
			UserPlayer player = new UserPlayer();
			player.setUid(user.getUid());
			player.setAppHandler(getAppHandler());
			mPlayers[wChairID] = player;
			mPlayers[wChairID].SetTable(this);
			mPlayers[wChairID].SetChairID(wChairID);
			
			//三个人位置对应的牌
			CMD_S_UserEnterTable UserEnterTable = new CMD_S_UserEnterTable();

			UserEnterTable.dwUserID = user.getUid();
			UserEnterTable.wCharID = wChairID;
			UserEnterTable.lBaseScore = m_lCellScore;
			UserEnterTable.szName = user.getNickName(null);
			String sData = UserEnterTable.getJsonData();
			SendTableData(Constants.INVALID_CHAIR, Constants.SUB_GR_USER_ENTER_TABLE, UserEnterTable, 0, sData);
		}
	}
	//头像
	void SendAvatar(int _Uid) {
		int wChairID = FindSeat(_Uid);
		if (wChairID == Constants.INVALID_CHAIR) {
			return;
		}

		String iter = dthall.getInstance().Handle_OnGetUserAvatar(_Uid);

		SUBCMD_S_Avatar cmd = new SUBCMD_S_Avatar();
		cmd.m_lUid = _Uid;
		if (iter != null) {
			cmd.szAvatarURL = iter;
		} else {
			cmd.szAvatarURL = PublishDef.getDefaultHeadAvatar();
		}

		SendData(Constants.INVALID_CHAIR, cmd.getJsonData());

	}
	
	// 表情
		void Handle_onBiaoQing(int _Uid, String vecArg[]) {
			int wChairID = FindSeat(_Uid);
			if (wChairID == Constants.INVALID_CHAIR) {
				// printf("Handle_onBiaoQing Error _Uid(%d)(%d)\n", _Uid, wChairID);
				return;
			}
			if (vecArg.length < 2)
				return;
			int index = Constants.atoi(vecArg[1]);

			SUBCMD_S_BiaoQing cmd = new SUBCMD_S_BiaoQing();
			cmd.m_lUid = _Uid;
			cmd.m_wUserChairID = wChairID;
			cmd.m_iBiaoQingIndex = index;

			SendData(Constants.INVALID_CHAIR, cmd.getJsonData());
		}
		// 语音
		void Handle_onYuYin(int _Uid, String vecArg[]) {
			int wChairID = FindSeat(_Uid);
			if (wChairID == Constants.INVALID_CHAIR) {
				// printf("Handle_onBiaoQing Error _Uid(%d)(%d)\n", _Uid, wChairID);
				return;
			}
			if (vecArg.length < 2)
				return;
			int index = Constants.atoi(vecArg[1]);

			SUBCMD_S_YuYin cmd = new SUBCMD_S_YuYin();
			cmd.m_lUid = _Uid;
			cmd.m_wUserChairID = wChairID;
			cmd.m_iYuYinIndex = index;

			SendData(Constants.INVALID_CHAIR, cmd.getJsonData());
		}

		// 聊天
		void Handle_onChat(int _Uid, String vecArg[]) {
			int wChairID = FindSeat(_Uid);
			if (wChairID == Constants.INVALID_CHAIR) {
				// printf("Handle_onBiaoQing Error _Uid(%d)(%d)\n", _Uid, wChairID);
				return;
			}
			if (vecArg.length < 2)
				return;
			String strContent = vecArg[1];

			SUBCMD_S_Chat cmd = new SUBCMD_S_Chat();
			cmd.m_lUid = _Uid;
			cmd.m_wUserChairID = wChairID;
			cmd.szContent = strContent;

			SendData(Constants.INVALID_CHAIR, cmd.getJsonData());
		}	
		
		// 语音
		void Handle_onVoice(int _Uid, String vecArg[]) {
			int wChairID = FindSeat(_Uid);
			if (wChairID == Constants.INVALID_CHAIR) {
				// printf("Handle_onBiaoQing Error _Uid(%d)(%d)\n", _Uid, wChairID);
				return;
			}
			if (vecArg.length < 3)
				return;
			int seconds = Constants.atoi(vecArg[1]);
			String strVoiceURL = vecArg[2];

			SUBCMD_S_Voice cmd = new SUBCMD_S_Voice();
			cmd.m_lUid = _Uid;
			cmd.m_wUserChairID = wChairID;
			cmd.seconds = seconds;
			cmd.szVoiceURL = strVoiceURL;

			SendData(Constants.INVALID_CHAIR, cmd.getJsonData());
		}
		void Handle_onVoiceMsg(int _Uid, String[] vecArg) {
			int wChairID = FindSeat(_Uid);
			if (wChairID == Constants.INVALID_CHAIR) {
				return;
			}
			float seconds = Float.parseFloat(vecArg[1]);
			
			SUBCMD_S_VoiceMsg cmd = new SUBCMD_S_VoiceMsg();
			cmd.m_lUid = _Uid;
			cmd.m_wUserChairID = wChairID;
			cmd.seconds = seconds;
			
			cmd.data = vecArg[2];
			cmd.m_maxClip = Integer.parseInt(vecArg[3]);
			cmd.m_currClip = Integer.parseInt(vecArg[4]);
			SendData(Constants.INVALID_CHAIR,cmd.getJsonData());
		}
		void Handle_onExpr(int _Uid, String[] vecArg) {
			int wChairID = FindSeat(_Uid);
			if (wChairID == Constants.INVALID_CHAIR) {
				return;
			}
			int uid1 = Integer.parseInt(vecArg[1]);
			int uid2 = Integer.parseInt(vecArg[2]);
			int index = Integer.parseInt(vecArg[3]);
			
			SUBCMD_S_ExprMsg cmd = new SUBCMD_S_ExprMsg();
			cmd.m_uid1 = uid1;
			cmd.m_uid2 = uid2;
			cmd.m_index = index;
			
			SendData(Constants.INVALID_CHAIR,cmd.getJsonData());
		}
		// 文字
		void Handle_onText(int _Uid, String[] vecArg) {

			int wChairID = FindSeat(_Uid);
			if (wChairID == Constants.INVALID_CHAIR) {
				return;
			}
			String strContent = vecArg[1];

			strContent = string_replace(strContent, "|", ".");
			strContent = string_replace(strContent, "#", ".");
			strContent = string_replace(strContent, ",", ".");
			strContent = string_replace(strContent, "\\", ".");
			strContent = string_replace(strContent, "'", ".");
			strContent = string_replace(strContent, "\"", ".");

			SUBCMD_S_Text cmd = new SUBCMD_S_Text();
			cmd.m_lUid = _Uid;
			cmd.m_wUserChairID = wChairID;
			cmd.szContent = strContent;
			SendData(Constants.INVALID_CHAIR, cmd.getJsonData());
		}
		private String string_replace(String strContent, String string, String string2) {
			return strContent.replace(string, string2);
		}
		
		// 请求解散房间
		void Handle_onTryDismissRoom(int _Uid, String vecArg[]) {
			int bySeatID = FindSeat(_Uid);
			if (bySeatID == Constants.INVALID_CHAIR) {
				// printf("Handle_onBiaoQing Error _Uid(%d)(%d)\n", _Uid, bySeatID);
				return;
			}
			if (vecArg.length < 2)
				return;

			String attachInfo = vecArg[1];
			if(attachInfo.equals("fzquit")){
				//房主请求直接退出
				OnEventGameEnd(0,null, Constants.GAME_END_DISMISS);
				return;
			}
			
			int cntUser = 0;
			int cntOnline = 0;
			int cntOffline = 0;
			for (int i = 0; i < 3; i++) {
				if (m_pIUserItem[i].dwUserID > 0 && (m_pIUserItem[i].isAndroidUser == 0 || m_pIUserItem[i].isAndroidUser == 2) ) {
					cntUser++;
				}
			}
			for (int i = 0; i < 3; i++)
			{
				if (m_pIUserItem[i].dwUserID > 0 && (m_pIUserItem[i].isAndroidUser == 0 || m_pIUserItem[i].isAndroidUser == 2))
				{
					if (m_pIUserItem[i].cbOnline == Constants.US_OFFLINE)
					{
						cntOffline++;
					}
					else{
						cntOnline++;
					}
				}
			}		
			if (cntUser > 1) {
				if (m_dismissTimer == 0) {
					m_dismissTimer = Constants.time(null);
				}
				m_byAgreeDismiss[bySeatID] = 1;
				
				int cntAgree = 0;

				for (int i = 0; i < 3; i++) {
					if (m_byAgreeDismiss[i] > 0 || (m_pIUserItem[i].dwUserID > 0 && Constants.US_LOOKON == m_pIUserItem[i].cbUserStatus)) {
						cntAgree++;
					}
				}
				
				if (cntAgree >= 2 && cntAgree >= cntUser - 1) {
					OnEventGameEnd(0,null, Constants.GAME_END_DISMISS);
				}else{
					SUBCMD_S_TryDismissRoom cmd = new SUBCMD_S_TryDismissRoom();
					cmd.lUid = _Uid;
					cmd.dwTableID = m_dwTableID;
					cmd.szNickName = m_pIUserItem[bySeatID].szNickName;
					
					for(int i = 0; i < 3; i ++)
					{	// 旁观者不参与解散房间
						if(m_pIUserItem[i].dwUserID > 0 && Constants.US_LOOKON != m_pIUserItem[i].cbUserStatus)
						{
							SendData(m_pIUserItem[i].dwUserID, cmd.getJsonData());
						}
					}
					
				
					if (cntOnline == 1) {
						OnEventGameEnd(0,null,Constants.GAME_END_DISMISS);
						m_dismissTimer = 0;
					}else{
						//处理robot，同意
						boolean hasRobot = false;
						for(int i = 0;i < 3;i++){
							if( m_pIUserItem[i].isAndroidUser == 2){
								hasRobot = true;
								break;
							}
						}
						if(hasRobot){
							try{
								class AgreeTask extends TimerTask{
				
									@Override
									public void run() {
										for(int i = 0;i < 3;i++){
											if( m_pIUserItem[i].isAndroidUser == 2){
												if(m_isDestoryed == false && m_byAgreeDismiss[i] == 0 && CommonDef.getRandomInt(100) > 50){
													String vecArg[] = {"agree_dismissroom","" + m_pIUserItem[i].dwUserID};
													Handle_onAgreeDismissRoom(m_pIUserItem[i].dwUserID,vecArg);
													return;
												}
											}
										}
									}					
								}
								Timer timer = new Timer();
								AgreeTask task = new AgreeTask();
								timer.schedule(task, 2000,2000);
							}catch(Exception e){
								
							}
						}
					}
				}			
			} else {
				OnEventGameEnd(0, null,Constants.GAME_END_DISMISS);
			}

		}	
		
		void Handle_onAgreeDismissRoom(int _Uid, String vecArg[]) {
			int bySeatID = FindSeat(_Uid);
			if (bySeatID == Constants.INVALID_CHAIR) {
				// printf("Handle_onBiaoQing Error _Uid(%d)(%d)\n", _Uid, bySeatID);
				return;
			}
			if (vecArg.length < 2)
				return;
			m_byAgreeDismiss[bySeatID] = 1;

			SUBCMD_S_AgreeDismissRoom cmd = new SUBCMD_S_AgreeDismissRoom();
			cmd.lUid = _Uid;
			cmd.dwTableID = m_dwTableID;
			cmd.szNickName = m_pIUserItem[bySeatID].szNickName;

			SendData(Constants.INVALID_CHAIR, cmd.getJsonData());

			if (bySeatID == 0 && m_bTableStarted == false) {
				OnEventGameEnd(0, null,Constants.GAME_END_DISMISS);
				return;
			}
			int cntAgree = 0;
			for (int i = 0; i < 3; i++) {
				if (m_byAgreeDismiss[i] > 0) {
					cntAgree++;
				}
			}
			int cntUser = 0;
			for (int i = 0; i < 3; i++) {
				if (m_pIUserItem[i].dwUserID > 0 && (m_pIUserItem[i].isAndroidUser == 0 || m_pIUserItem[i].isAndroidUser == 2)) {
					cntUser++;
				}
			}
			if (cntAgree >= 2 && cntAgree >= cntUser - 1) {
				OnEventGameEnd(0, null,Constants.GAME_END_DISMISS);
			}
		}
		void Handle_InBack(int _Uid,String[] vecArg){
			int wChairID = FindSeat(_Uid);
			if (wChairID == Constants.INVALID_CHAIR) {
				return;
			}

			SUBCMD_S_InBack cmd = new SUBCMD_S_InBack();
			cmd.byActionUser = wChairID;
			SendData(Constants.INVALID_CHAIR, cmd.getJsonData());
		}
		void Handle_InFore(int _Uid,String[] vecArg){
			int wChairID = FindSeat(_Uid);
			if (wChairID == Constants.INVALID_CHAIR) {
				return;
			}

			SUBCMD_S_InFore cmd = new SUBCMD_S_InFore();
			cmd.byActionUser = wChairID;
			SendData(Constants.INVALID_CHAIR, cmd.getJsonData());
		}

		void Handle_GameIap(int _Uid,String vecArg[]){
			int wChairID = FindSeat(_Uid);
			if (wChairID == Constants.INVALID_CHAIR) {
				return;
			}
			SHMUser user = dthall.getInstance().getUserInfo(_Uid);
			if(user == null){
				return;
			}
			SUBCMD_S_GameIap cmd = new SUBCMD_S_GameIap();
			cmd.uid = _Uid;
			cmd.seat = wChairID;
			if(this.isDwcType()){
				cmd.coin = user.getRmb1v1Value();
				m_pIUserItem[wChairID].lUserRmb = cmd.coin;
			}else{
				cmd.coin = user.getCoin(0);
				m_pIUserItem[wChairID].lUserCoin = (int) cmd.coin;
			}
			SendData(Constants.INVALID_CHAIR,cmd.getJsonData());
		}
		void Handle_onRefuseDismissRoom(int _Uid, String vecArg[]) {
			int bySeatID = FindSeat(_Uid);
			if (bySeatID == Constants.INVALID_CHAIR) {
				// printf("Handle_onBiaoQing Error _Uid(%d)(%d)\n", _Uid, bySeatID);
				return;
			}
			if (vecArg.length < 2)
				return;

			m_dismissTimer = 0;
			m_byAgreeDismiss[0] = 0;
			m_byAgreeDismiss[1] = 0;
			m_byAgreeDismiss[2] = 0;
		
			SUBCMD_S_RefuseDismissRoom cmd = new SUBCMD_S_RefuseDismissRoom();
			cmd.lUid = _Uid;
			cmd.dwTableID = m_dwTableID;
			cmd.szNickName = m_pIUserItem[bySeatID].szNickName;

			SendData(Constants.INVALID_CHAIR, cmd.getJsonData());
		}
	
	public boolean SendData(int wChairID, String sData) {
		// 群发用户
		if (wChairID == Constants.INVALID_CHAIR) {
			for (short i = 0; i < m_pIUserItem.length; i++) {
				if (m_pIUserItem[i].dwUserID > 0) {
					if (m_pIUserItem[i].isAndroidUser == 0) {
						dthall.getInstance().onSend(m_pIUserItem[i].dwUserID, sData);
					} else {
						// mPlayers[i].SendGameMessage(wSubCmdID, pData,
						// wDataSize, data);
					}
				}
			}

			return true;
		} else {
			if (wChairID >= m_pIUserItem.length) {
				dthall.getInstance().onSend(wChairID, sData);
			} else if (m_pIUserItem[wChairID].dwUserID > 0) {
				if (m_pIUserItem[wChairID].isAndroidUser == 0) {
					dthall.getInstance().onSend(m_pIUserItem[wChairID].dwUserID, sData);
				} else {
				}
				return true;
			}
		}

		return false;
	}
	
	void onLogin(int uid) {
		SHMUser user = null;
		if ((user = dthall.getInstance().getUserInfo(uid)) != null) {
			Packet_LoginResult rData = new Packet_LoginResult();
			rData.m_wMsgType = Constants.PktID_LoginResult;
			rData.UserData.dwUserID = uid;
			rData.UserData.szName = user.getNickName(null);
			rData.UserData.lScore = user.getCoin(0);
			String jsonData = rData.getJsonData();
			onSend(user.getUid(), jsonData);
		}
	}
	public int OnDealDt = 0;
	public  long currDealTime1 = 0;
	@Override
	public void OnDeal(int dt) {
		int fenmu = 10 + CommonDef.getRandomInt(10);
		OnDealDt += (int)(dt / fenmu);
		if (OnDealDt > 1) {
			int  dtInt = (int)OnDealDt;
			Update(dtInt);
			OnDealDt -= dtInt;
		}
		if(currDealTime1 == 0){
			currDealTime1 = System.currentTimeMillis();
		}else{
			long time = System.currentTimeMillis();
			if((time - currDealTime1) >= 1000){
				currDealTime1 = time;
			}else{
				return;
			}
		}
		if(this.isGoldType() || this.isDwcType()){
			addRobotUser();
		}
		if(m_aiDelayTime > 0){
			m_aiDelayTime--;
		}
		if(m_aiDelayTime <= 0)
			OnDealRobot();
	}
	public void OnDealRobot(){
		if (m_curStage == "STAGE_JIESUAN") {
			if(CommonDef.getRandomInt(100) < 60){
				for (int wChairID = 0; wChairID < 3; wChairID++) {
					if (m_pIUserItem[wChairID].isAndroidUser == 2) {
						if(this.isGoldType()){
							if(m_pIUserItem[wChairID].cbUserStatus != Constants.US_READY){
								if(m_pIUserItem[wChairID].lUserCoin < m_lichang){
									//做一个delay，更真实
									if(this.m_autoGameIapDelay > 0){
										this.m_autoGameIapDelay--;
										return;
									}else if(this.m_autoGameIapDelay == 0){
										this.m_autoGameIapDelay = 10;
									}
									int [] applylist = {18888 + 2188,18888 + 2188,28888 + 2188,28888 + 2188,188888 + 2188,288888 + 2188,m_lichang + 1888};
									int applynum = 0;
									while(applynum < m_lichang){
										applynum = applylist[(int) (Math.random() * applylist.length)];
									}
									int gold = GoldMgr.getInstance().applyRobotGold(applynum);
									if(gold == 0.0){
										boolean hasdissmisstry = false;
										for(int k = 0;k < 5;k++){
											if(k == wChairID){
												continue;
											}
											if(m_byAgreeDismiss[k] == 1){
												hasdissmisstry = true;
											}
										}
										if(!hasdissmisstry && m_byAgreeDismiss[wChairID] != 1){
											String vecArg[] = {"normaluser","" + m_pIUserItem[wChairID].dwUserID};
											Handle_onTryDismissRoom(m_pIUserItem[wChairID].dwUserID, vecArg);
										}
										return;
									}else{
										SHMUser user = dthall.getInstance().getUserInfo(m_pIUserItem[wChairID].dwUserID);
										m_pIUserItem[wChairID].lUserCoin += gold;
										user.addApplyNum(gold);
										user.getCoin(gold);
										Handle_GameIap(m_pIUserItem[wChairID].dwUserID, new String[2]);
									}
								}else{
									if(CommonDef.getRandomInt(100) < 70){
										StartGame(m_pIUserItem[wChairID].dwUserID);
									}
								}
							}
						}else if(this.isDwcType()){
							if(m_pIUserItem[wChairID].cbUserStatus != Constants.US_READY){
								if(m_pIUserItem[wChairID].lUserRmb < m_lichang){
									//做一个delay，更真实
									if(this.m_autoGameIapDelay > 0){
										this.m_autoGameIapDelay--;
										return;
									}else if(this.m_autoGameIapDelay == 0){
										this.m_autoGameIapDelay = 10;
									}
									double [] applylist = {49.0,49.0,49.0,199.0,100.0,499.0,1299.0,1000.0,2000.0,m_lichang + 99.0};
									double applynum = 0.0;
									while(applynum < m_doubleDiFen){
										applynum = applylist[(int) (Math.random() * applylist.length)];
									}
									double rmb = GoldMgr.getInstance().applyRobotRmb(applynum);
									if(rmb == 0.0){
										boolean hasdissmisstry = false;
										for(int k = 0;k < 5;k++){
											if(k == wChairID){
												continue;
											}
											if(m_byAgreeDismiss[k] == 1){
												hasdissmisstry = true;
											}
										}
										if(!hasdissmisstry && m_byAgreeDismiss[wChairID] != 1){
											String vecArg[] = {"normaluser","" + m_pIUserItem[wChairID].dwUserID};
											Handle_onTryDismissRoom(m_pIUserItem[wChairID].dwUserID, vecArg);
										}
										return;
									}else{
										SHMUser user = dthall.getInstance().getUserInfo(m_pIUserItem[wChairID].dwUserID);
										m_pIUserItem[wChairID].lUserRmb += rmb;
										user.addApplyNum(rmb);
										user.addRmb1v1Value(rmb);
										Handle_GameIap(m_pIUserItem[wChairID].dwUserID, new String[2]);
									}
								}else{
									if(CommonDef.getRandomInt(100) < 70){
										StartGame(m_pIUserItem[wChairID].dwUserID);
									}
								}
							}
						}
					}
				}
			}
		}
	}
	public int m_DealTime = 0;
	@Override
	public int getDealTime() {
		return m_DealTime;
	}

	@Override
	public String getRoomInfo() {
		// TODO 自动生成的方法存根
		return null;
	}

	@Override
	public int getPlayerCount() {
		int cntPlayer = 0;
		for (int i = 0; i < 3; i++) {
			if (m_pIUserItem[i].dwUserID > 0) {
				cntPlayer++;
			}
		}
		return cntPlayer;
	}

	@Override
	public int getCostGem() {
		return m_byCostGem;
	}

	@Override
	public int getStatus() {
		if(m_bGameStarted == false)
		{
			return 0;
		}
		return 1;
	}

	@Override
	public String getRoomDesc() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public int getCellScore() {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public int getMinScore() {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public String getPayway() {
		// TODO Auto-generated method stub
		return m_payWay;
	}

	@Override
	public String GetRoundInfo() {
		return "" + m_byRound + "/" +  m_byMaxRound;
	}
}
